dhonnoll78
22nd February 2008, 17:31
I have a line of sed code in a script that is to pull from a .txt file that looks like this:
/dev/sda= 74 GB
/dev/sdb= 74 GB
drive1=`cat /tmp/drives.txt | sed -e 's/^.* \([[:digit:]]\{2,\}\) GB.*/\1/' `
drive2=`cat /tmp/drives.txt | sed -e 's/^.* \([[:digit:]]\{2,\}\) GB.*/\1/' `
echo "Drive 1 $drive1">>/tmp/mynewfile.txt
echo "Drive 2 $drive2">>/tmp/mynewfile.txt
The output looks like this:
Drive 1 74
74
Drive 2 74
74
Is it possible to get sed to find the first digit, yank it as a variable and stop, then use sed to find the second digit yank it as a separate variable and stop?
I want it to look like this
Drive 1 74
Drive 2 74
I am only interested in that 74 really or 34 in some cases which is what I am really trying to find out
/dev/sda= 74 GB
/dev/sdb= 74 GB
drive1=`cat /tmp/drives.txt | sed -e 's/^.* \([[:digit:]]\{2,\}\) GB.*/\1/' `
drive2=`cat /tmp/drives.txt | sed -e 's/^.* \([[:digit:]]\{2,\}\) GB.*/\1/' `
echo "Drive 1 $drive1">>/tmp/mynewfile.txt
echo "Drive 2 $drive2">>/tmp/mynewfile.txt
The output looks like this:
Drive 1 74
74
Drive 2 74
74
Is it possible to get sed to find the first digit, yank it as a variable and stop, then use sed to find the second digit yank it as a separate variable and stop?
I want it to look like this
Drive 1 74
Drive 2 74
I am only interested in that 74 really or 34 in some cases which is what I am really trying to find out