Extract substring after delimiter using GNU awk or awk
5,068
Please find the command
echo "/dev/sda: ST500LT012-9WS142: 47°C" | awk -F ":" '{print $3}'
output:
echo "/dev/sda: ST500LT012-9WS142: 47°C" | awk -F ":" '{print $3}'
47°C
Related videos on Youtube
Author by
Twissell
Updated on September 18, 2022Comments
-
Twissell over 1 year
I would like to extract substring after colon delimiter for my practical needs using GNU awk utility. For example I can extract the temperature of hdd value using
cut
as followshddtemp /dev/sda | cut -d ':' -f3
The same example written in
sed
hddtemp /dev/sda | sed 's/.*\://'
For glory of Saint Completeness and GNU Trinity (awk, cut, sed) I wonder, can GNU
awk
do such thing?Sample input:
/dev/sda: ST500LT012-9WS142: 47°C
Required output:
47°C
-
Praveen Kumar BS over 5 yearsPlease post sample input and required output
-
Twissell over 5 years@PraveenKumarBS, done!
-
αғsнιη over 5 years
... |awk '{ print $NF }'
-
Twissell over 5 years@don_crissti, Yep!
awk -F ":" '{print $NF}'
also works well. But in that topic the answer wasn't accepted. -
don_crissti over 5 years(Sadly...) The best answer isn't always the accepted one...
-