I'm trying to split the value using awk command into three parts. Need help to break into 3.
Content = 1. 11683 (<server01>: du.size[/,free] : 0.5 % 2. 21683 (<server02>: du.size[/,free] : 1.5 % 3. 31683 (<server03>: du.size[/,free] : 3.5 %
I want the above content to break into 3 lines in a numbering system.
Sample output required :
1. 11683 (<server01>: du.size[/,free] : 0.5 %
2. 21683 (<server02>: du.size[/,free] : 1.5 %
3. 31683 (<server03>: du.size[/,free] : 3.5 %
I have tried by the following commands :
echo $content | awk -F"3. " '{ print $2 }'
and i get
31683 (<server03>: du.size[/,free] : 3.5 %
Similarly for others, But still failed to get sample output in proper numbering format as shown above.
Can any one help me on this ?
The %
symbol looks like a good candidate to split on. Try:
sed 's/% /%\n/g'
Testing:
echo "1. 11683 (<server01>: du.size[/,free] : 0.5 % 2. 21683 (<server02>: du.size[/,free] : 1.5 % 3. 31683 (<server03>: du.size[/,free] : 3.5 %" | sed 's/% /%\n/g'
Results:
1. 11683 (<server01>: du.size[/,free] : 0.5 %
2. 21683 (<server02>: du.size[/,free] : 1.5 %
3. 31683 (<server03>: du.size[/,free] : 3.5 %
You could use sed
instead:
sed "s#[^^]\([0-9]\.\) #\n\1 #g"
Example:
[~/Desktop]
==> echo "1. 11683 (<server01>: du.size[/,free] : 0.5 % 2. 21683 (<server02>: du.size[/,free] : 1.5 % 3. 31683 (<server03>: du.size[/,free] : 3.5 %" | sed "s#[^^]\([0-9]
\.\) #\n\1 #g"
1. 11683 (<server01>: du.size[/,free] : 0.5 %
2. 21683 (<server02>: du.size[/,free] : 1.5 %
3. 31683 (<server03>: du.size[/,free] : 3.5 %
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With