how to print the matching value from same line, which has multiple Delimiter?
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I have a File under Linux /tmp/volume.log and the content is:
[id:1091666, name:root, deviceName:/dev/sda, maxStorage:107374182400, unitNumber:0, displayOrder:0, rootVolume:true],[id:1091851, name:/var/log/devops|40GB;/home/devops|150GB, deviceName:/dev/sdb, maxStorage:289910292480, unitNumber:1, displayOrder:1, rootVolume:false]],
It will be in single line. This file is generated by some other script.
My Aim is to find the non-root volume disk and parse it to LVM Commands as Variable to extend or create new volumes, at the time of OS Build.
In the above Example.
There are two disks,
1 - sda which is root disk, (if rootVolume is true it is root disk)
2 - sdb which is non root disk (if rootVolume is false it is non root disk)
I have to grep only
rootVolume=false
and grep then
deviceName:/dev/sdb
followed by:
name:/var/log/devops|40GB;/home/devops|150GB
Once I parse all the above in to Variables, I can call those variables in the Commands like
#!/bin/bash
Disk_name=/dev/sdb
Size_Value=40G
LV_name=var_log_devops
Mount_Point=/var/log/devops
sudo pvcreate $Disk_name
sudo vgcreate vgrp01 $Disk_name
sudo lvcreate -L $Size_Value -n $var_log_devops vgrp01
sudo mkfs.xfs $var_log_devops
sudo mkdir -p $/var/log/devops
sudo mount $var_log_devops $/var/log/devops
Right now I am struck with, Extracting the Values from the Text file, becasue they are in single line and multiple Delimiters are present.
shell-script text-processing awk sed perl
add a comment |Â
up vote
1
down vote
favorite
I have a File under Linux /tmp/volume.log and the content is:
[id:1091666, name:root, deviceName:/dev/sda, maxStorage:107374182400, unitNumber:0, displayOrder:0, rootVolume:true],[id:1091851, name:/var/log/devops|40GB;/home/devops|150GB, deviceName:/dev/sdb, maxStorage:289910292480, unitNumber:1, displayOrder:1, rootVolume:false]],
It will be in single line. This file is generated by some other script.
My Aim is to find the non-root volume disk and parse it to LVM Commands as Variable to extend or create new volumes, at the time of OS Build.
In the above Example.
There are two disks,
1 - sda which is root disk, (if rootVolume is true it is root disk)
2 - sdb which is non root disk (if rootVolume is false it is non root disk)
I have to grep only
rootVolume=false
and grep then
deviceName:/dev/sdb
followed by:
name:/var/log/devops|40GB;/home/devops|150GB
Once I parse all the above in to Variables, I can call those variables in the Commands like
#!/bin/bash
Disk_name=/dev/sdb
Size_Value=40G
LV_name=var_log_devops
Mount_Point=/var/log/devops
sudo pvcreate $Disk_name
sudo vgcreate vgrp01 $Disk_name
sudo lvcreate -L $Size_Value -n $var_log_devops vgrp01
sudo mkfs.xfs $var_log_devops
sudo mkdir -p $/var/log/devops
sudo mount $var_log_devops $/var/log/devops
Right now I am struck with, Extracting the Values from the Text file, becasue they are in single line and multiple Delimiters are present.
shell-script text-processing awk sed perl
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have a File under Linux /tmp/volume.log and the content is:
[id:1091666, name:root, deviceName:/dev/sda, maxStorage:107374182400, unitNumber:0, displayOrder:0, rootVolume:true],[id:1091851, name:/var/log/devops|40GB;/home/devops|150GB, deviceName:/dev/sdb, maxStorage:289910292480, unitNumber:1, displayOrder:1, rootVolume:false]],
It will be in single line. This file is generated by some other script.
My Aim is to find the non-root volume disk and parse it to LVM Commands as Variable to extend or create new volumes, at the time of OS Build.
In the above Example.
There are two disks,
1 - sda which is root disk, (if rootVolume is true it is root disk)
2 - sdb which is non root disk (if rootVolume is false it is non root disk)
I have to grep only
rootVolume=false
and grep then
deviceName:/dev/sdb
followed by:
name:/var/log/devops|40GB;/home/devops|150GB
Once I parse all the above in to Variables, I can call those variables in the Commands like
#!/bin/bash
Disk_name=/dev/sdb
Size_Value=40G
LV_name=var_log_devops
Mount_Point=/var/log/devops
sudo pvcreate $Disk_name
sudo vgcreate vgrp01 $Disk_name
sudo lvcreate -L $Size_Value -n $var_log_devops vgrp01
sudo mkfs.xfs $var_log_devops
sudo mkdir -p $/var/log/devops
sudo mount $var_log_devops $/var/log/devops
Right now I am struck with, Extracting the Values from the Text file, becasue they are in single line and multiple Delimiters are present.
shell-script text-processing awk sed perl
I have a File under Linux /tmp/volume.log and the content is:
[id:1091666, name:root, deviceName:/dev/sda, maxStorage:107374182400, unitNumber:0, displayOrder:0, rootVolume:true],[id:1091851, name:/var/log/devops|40GB;/home/devops|150GB, deviceName:/dev/sdb, maxStorage:289910292480, unitNumber:1, displayOrder:1, rootVolume:false]],
It will be in single line. This file is generated by some other script.
My Aim is to find the non-root volume disk and parse it to LVM Commands as Variable to extend or create new volumes, at the time of OS Build.
In the above Example.
There are two disks,
1 - sda which is root disk, (if rootVolume is true it is root disk)
2 - sdb which is non root disk (if rootVolume is false it is non root disk)
I have to grep only
rootVolume=false
and grep then
deviceName:/dev/sdb
followed by:
name:/var/log/devops|40GB;/home/devops|150GB
Once I parse all the above in to Variables, I can call those variables in the Commands like
#!/bin/bash
Disk_name=/dev/sdb
Size_Value=40G
LV_name=var_log_devops
Mount_Point=/var/log/devops
sudo pvcreate $Disk_name
sudo vgcreate vgrp01 $Disk_name
sudo lvcreate -L $Size_Value -n $var_log_devops vgrp01
sudo mkfs.xfs $var_log_devops
sudo mkdir -p $/var/log/devops
sudo mount $var_log_devops $/var/log/devops
Right now I am struck with, Extracting the Values from the Text file, becasue they are in single line and multiple Delimiters are present.
shell-script text-processing awk sed perl
shell-script text-processing awk sed perl
edited 42 mins ago


Jeff Schaller
33.1k849111
33.1k849111
asked 55 mins ago
user3179298
113
113
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
3
down vote
You can use the command cut
something like:
cat /tmp/volume.log | cut -d, -f14 | tr -d "]]"
rootVolume=false
make it a variable:
rootvolume=$(cat /tmp/volume.log | cut -d, -f14 | tr -d "]]")
cat /tmp/volume.log | cut -d, -f3
deviceName:/dev/sda
cat /tmp/volume.log | cut -d, -f9
name:/var/log/devops|40GB;/home/devops|150GB
I gave you an example of the text file, but in real we might have more disk's. So I have to grep only the rootvolume=false and once the match is found. Then I need to get the false boot disk name. Then the other partition.
– user3179298
36 mins ago
Hi @user3179298. You can change-f14
to match the information you want in the file. Does this make sense?
– Goro
34 mins ago
Hello Gora, the Field will change server to server. Some times the field 14 will have root volume disk.
– user3179298
4 mins ago
No worries, I will tweak it for you. I thought you have standard files as provided in your example!
– Goro
3 mins ago
I have a logic, but not sure how to get that done. i see every disk are start and end with [ ..... ],[.....],[.....] So, i need to grep for root volume=false, then need to take that [......rootvolume=false ] as variable and use sed or cut to get the disk and other volume information's. then i will parse it to the script for LVM creation. But not sure how to :(
– user3179298
39 secs ago
add a comment |Â
up vote
0
down vote
How far would this get you:
awk -vRS="]" '/rootVolume:false/ for (i=1; i<=NF; i++) if ($i ~ /name' file
name:/var/log/devops|40GB;/home/devops|150GB,
deviceName:/dev/sdb,
It splits the single line at ]
, then scans through all fields to find the target ones, and prints them. You could read the result into shell variables like so, then:
read VARA VARB REST <<< $(awk -vRS="],*" -vORS=" " '/rootVolume:false/ for (i=1; i<=NF; i++) if ($i ~ /name' file)
echo $VARA
name:/var/log/devops|40GB;/home/devops|150GB,
echo $VARB
deviceName:/dev/sdb,
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
You can use the command cut
something like:
cat /tmp/volume.log | cut -d, -f14 | tr -d "]]"
rootVolume=false
make it a variable:
rootvolume=$(cat /tmp/volume.log | cut -d, -f14 | tr -d "]]")
cat /tmp/volume.log | cut -d, -f3
deviceName:/dev/sda
cat /tmp/volume.log | cut -d, -f9
name:/var/log/devops|40GB;/home/devops|150GB
I gave you an example of the text file, but in real we might have more disk's. So I have to grep only the rootvolume=false and once the match is found. Then I need to get the false boot disk name. Then the other partition.
– user3179298
36 mins ago
Hi @user3179298. You can change-f14
to match the information you want in the file. Does this make sense?
– Goro
34 mins ago
Hello Gora, the Field will change server to server. Some times the field 14 will have root volume disk.
– user3179298
4 mins ago
No worries, I will tweak it for you. I thought you have standard files as provided in your example!
– Goro
3 mins ago
I have a logic, but not sure how to get that done. i see every disk are start and end with [ ..... ],[.....],[.....] So, i need to grep for root volume=false, then need to take that [......rootvolume=false ] as variable and use sed or cut to get the disk and other volume information's. then i will parse it to the script for LVM creation. But not sure how to :(
– user3179298
39 secs ago
add a comment |Â
up vote
3
down vote
You can use the command cut
something like:
cat /tmp/volume.log | cut -d, -f14 | tr -d "]]"
rootVolume=false
make it a variable:
rootvolume=$(cat /tmp/volume.log | cut -d, -f14 | tr -d "]]")
cat /tmp/volume.log | cut -d, -f3
deviceName:/dev/sda
cat /tmp/volume.log | cut -d, -f9
name:/var/log/devops|40GB;/home/devops|150GB
I gave you an example of the text file, but in real we might have more disk's. So I have to grep only the rootvolume=false and once the match is found. Then I need to get the false boot disk name. Then the other partition.
– user3179298
36 mins ago
Hi @user3179298. You can change-f14
to match the information you want in the file. Does this make sense?
– Goro
34 mins ago
Hello Gora, the Field will change server to server. Some times the field 14 will have root volume disk.
– user3179298
4 mins ago
No worries, I will tweak it for you. I thought you have standard files as provided in your example!
– Goro
3 mins ago
I have a logic, but not sure how to get that done. i see every disk are start and end with [ ..... ],[.....],[.....] So, i need to grep for root volume=false, then need to take that [......rootvolume=false ] as variable and use sed or cut to get the disk and other volume information's. then i will parse it to the script for LVM creation. But not sure how to :(
– user3179298
39 secs ago
add a comment |Â
up vote
3
down vote
up vote
3
down vote
You can use the command cut
something like:
cat /tmp/volume.log | cut -d, -f14 | tr -d "]]"
rootVolume=false
make it a variable:
rootvolume=$(cat /tmp/volume.log | cut -d, -f14 | tr -d "]]")
cat /tmp/volume.log | cut -d, -f3
deviceName:/dev/sda
cat /tmp/volume.log | cut -d, -f9
name:/var/log/devops|40GB;/home/devops|150GB
You can use the command cut
something like:
cat /tmp/volume.log | cut -d, -f14 | tr -d "]]"
rootVolume=false
make it a variable:
rootvolume=$(cat /tmp/volume.log | cut -d, -f14 | tr -d "]]")
cat /tmp/volume.log | cut -d, -f3
deviceName:/dev/sda
cat /tmp/volume.log | cut -d, -f9
name:/var/log/devops|40GB;/home/devops|150GB
edited 33 mins ago
answered 40 mins ago
Goro
5,65552460
5,65552460
I gave you an example of the text file, but in real we might have more disk's. So I have to grep only the rootvolume=false and once the match is found. Then I need to get the false boot disk name. Then the other partition.
– user3179298
36 mins ago
Hi @user3179298. You can change-f14
to match the information you want in the file. Does this make sense?
– Goro
34 mins ago
Hello Gora, the Field will change server to server. Some times the field 14 will have root volume disk.
– user3179298
4 mins ago
No worries, I will tweak it for you. I thought you have standard files as provided in your example!
– Goro
3 mins ago
I have a logic, but not sure how to get that done. i see every disk are start and end with [ ..... ],[.....],[.....] So, i need to grep for root volume=false, then need to take that [......rootvolume=false ] as variable and use sed or cut to get the disk and other volume information's. then i will parse it to the script for LVM creation. But not sure how to :(
– user3179298
39 secs ago
add a comment |Â
I gave you an example of the text file, but in real we might have more disk's. So I have to grep only the rootvolume=false and once the match is found. Then I need to get the false boot disk name. Then the other partition.
– user3179298
36 mins ago
Hi @user3179298. You can change-f14
to match the information you want in the file. Does this make sense?
– Goro
34 mins ago
Hello Gora, the Field will change server to server. Some times the field 14 will have root volume disk.
– user3179298
4 mins ago
No worries, I will tweak it for you. I thought you have standard files as provided in your example!
– Goro
3 mins ago
I have a logic, but not sure how to get that done. i see every disk are start and end with [ ..... ],[.....],[.....] So, i need to grep for root volume=false, then need to take that [......rootvolume=false ] as variable and use sed or cut to get the disk and other volume information's. then i will parse it to the script for LVM creation. But not sure how to :(
– user3179298
39 secs ago
I gave you an example of the text file, but in real we might have more disk's. So I have to grep only the rootvolume=false and once the match is found. Then I need to get the false boot disk name. Then the other partition.
– user3179298
36 mins ago
I gave you an example of the text file, but in real we might have more disk's. So I have to grep only the rootvolume=false and once the match is found. Then I need to get the false boot disk name. Then the other partition.
– user3179298
36 mins ago
Hi @user3179298. You can change
-f14
to match the information you want in the file. Does this make sense?– Goro
34 mins ago
Hi @user3179298. You can change
-f14
to match the information you want in the file. Does this make sense?– Goro
34 mins ago
Hello Gora, the Field will change server to server. Some times the field 14 will have root volume disk.
– user3179298
4 mins ago
Hello Gora, the Field will change server to server. Some times the field 14 will have root volume disk.
– user3179298
4 mins ago
No worries, I will tweak it for you. I thought you have standard files as provided in your example!
– Goro
3 mins ago
No worries, I will tweak it for you. I thought you have standard files as provided in your example!
– Goro
3 mins ago
I have a logic, but not sure how to get that done. i see every disk are start and end with [ ..... ],[.....],[.....] So, i need to grep for root volume=false, then need to take that [......rootvolume=false ] as variable and use sed or cut to get the disk and other volume information's. then i will parse it to the script for LVM creation. But not sure how to :(
– user3179298
39 secs ago
I have a logic, but not sure how to get that done. i see every disk are start and end with [ ..... ],[.....],[.....] So, i need to grep for root volume=false, then need to take that [......rootvolume=false ] as variable and use sed or cut to get the disk and other volume information's. then i will parse it to the script for LVM creation. But not sure how to :(
– user3179298
39 secs ago
add a comment |Â
up vote
0
down vote
How far would this get you:
awk -vRS="]" '/rootVolume:false/ for (i=1; i<=NF; i++) if ($i ~ /name' file
name:/var/log/devops|40GB;/home/devops|150GB,
deviceName:/dev/sdb,
It splits the single line at ]
, then scans through all fields to find the target ones, and prints them. You could read the result into shell variables like so, then:
read VARA VARB REST <<< $(awk -vRS="],*" -vORS=" " '/rootVolume:false/ for (i=1; i<=NF; i++) if ($i ~ /name' file)
echo $VARA
name:/var/log/devops|40GB;/home/devops|150GB,
echo $VARB
deviceName:/dev/sdb,
add a comment |Â
up vote
0
down vote
How far would this get you:
awk -vRS="]" '/rootVolume:false/ for (i=1; i<=NF; i++) if ($i ~ /name' file
name:/var/log/devops|40GB;/home/devops|150GB,
deviceName:/dev/sdb,
It splits the single line at ]
, then scans through all fields to find the target ones, and prints them. You could read the result into shell variables like so, then:
read VARA VARB REST <<< $(awk -vRS="],*" -vORS=" " '/rootVolume:false/ for (i=1; i<=NF; i++) if ($i ~ /name' file)
echo $VARA
name:/var/log/devops|40GB;/home/devops|150GB,
echo $VARB
deviceName:/dev/sdb,
add a comment |Â
up vote
0
down vote
up vote
0
down vote
How far would this get you:
awk -vRS="]" '/rootVolume:false/ for (i=1; i<=NF; i++) if ($i ~ /name' file
name:/var/log/devops|40GB;/home/devops|150GB,
deviceName:/dev/sdb,
It splits the single line at ]
, then scans through all fields to find the target ones, and prints them. You could read the result into shell variables like so, then:
read VARA VARB REST <<< $(awk -vRS="],*" -vORS=" " '/rootVolume:false/ for (i=1; i<=NF; i++) if ($i ~ /name' file)
echo $VARA
name:/var/log/devops|40GB;/home/devops|150GB,
echo $VARB
deviceName:/dev/sdb,
How far would this get you:
awk -vRS="]" '/rootVolume:false/ for (i=1; i<=NF; i++) if ($i ~ /name' file
name:/var/log/devops|40GB;/home/devops|150GB,
deviceName:/dev/sdb,
It splits the single line at ]
, then scans through all fields to find the target ones, and prints them. You could read the result into shell variables like so, then:
read VARA VARB REST <<< $(awk -vRS="],*" -vORS=" " '/rootVolume:false/ for (i=1; i<=NF; i++) if ($i ~ /name' file)
echo $VARA
name:/var/log/devops|40GB;/home/devops|150GB,
echo $VARB
deviceName:/dev/sdb,
answered 46 secs ago
RudiC
1,5899
1,5899
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f472553%2fhow-to-print-the-matching-value-from-same-line-which-has-multiple-delimiter%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password