Search This Blog

Thursday, June 18, 2020

awk multiple field separators.

Using multiple field separators with awk and perl to convert "," to a newline.

Example:

echo "100(txt),528(smbw),529(smbt),530(smbn),10115(smbs)"|\
 perl -pe 's/,/\n/g'
100(txt)
528(smbw)
529(smbt)
530(smbn)
10115(smbs)

Using awk to just print the text between ().
echo "100(txt),528(smbw),529(smbt),530(smbn),10115(smbs)"|\
 perl -pe 's/,/\n/g'|\
 awk -F"[()]" '/smb/{print $2}'
smbw
smbt
smbn
smbs

Using awk to just print the text between [].

awk -F'[][]' and awk -F'[[]]' will not work.