BASH extract fields from string
Posted 04-05-2020 at 05:19 PM by karanis
https://en.wikibooks.org/wiki/Cut
link above have nice examples
Examples of use of similar tools in cut's domain:
echo a b|awk '{print $2}'
Displays "b", separating fields by any number of tabs or spaces. Thus, for awk, "b" is the 2nd field, while for cut -d" ", "b" is the 3rd field.
echo a b|awk '{print $2 $1}'
Displays "ba", preserving the order of the fields as specified.
echo a b|sed "s/ */ /g" |cut -f2 -d" "
Displays "b". Uses sed to first compact a sequence of spaces into a single space.
link above have nice examples
Examples of use of similar tools in cut's domain:
echo a b|awk '{print $2}'
Displays "b", separating fields by any number of tabs or spaces. Thus, for awk, "b" is the 2nd field, while for cut -d" ", "b" is the 3rd field.
echo a b|awk '{print $2 $1}'
Displays "ba", preserving the order of the fields as specified.
echo a b|sed "s/ */ /g" |cut -f2 -d" "
Displays "b". Uses sed to first compact a sequence of spaces into a single space.
Total Comments 0