Is there a way to nest lookups?

I want to change the format of each line in a file, and also run another lookup in one of the mapped groups.

As an example, I could have a simple three-column CSV file (without screens), which I would like to place in a different format.

sed -r 's/^([a-z]+),([a-z]+),([a-z]+)$/\1: \3 (\2)'
# would turn "comma,separated,values"
# into       "comma: values (separated)"

However, I also want to remove all the vowels from the second column, i.e. run s/[aeiou]//gon \2.

Is there a good solution to this nested permutation problem? Suppose both replacements are complex, and this was just an example.

My sed is not GNU sed version 4.0.

+5
source share
2 answers

( sed), . , , - , , , .

sed 'h;s/.*,([a-z]+),.*/(\1)/;s/[aeiou]//g;x;s/([a-z]+),[a-z]+,([a-z]+)/\1: \2 /;G;s/\n//'

: " , , , , , ( ), , ".

+1

, awk , .

echo "gaviidae,gruidae,picidae" | awk -F "," '{gsub(/[aeiou]/, "", $2); printf("%s: %s (%s)\n", $1, $3, $2)}'

:

gaviidae: picidae (grd)
0

All Articles