3 ms·
Awk lets you set both: $ echo -n "1,2,3|4,5|6|7,8,9,0" | awk 'BEGIN{FS=","; RS="|"} {print NF, $0}' 3 1,2,3 2 4,5 1 6 4 7,8,9,0 In fact, y
by sheetjs 13y ago
Awk lets you set both:
$ echo -n "1,2,3|4,5|6|7,8,9,0" | awk 'BEGIN{FS=","; RS="|"} {print NF, $0}'
3 1,2,3
2 4,5
1 6
4 7,8,9,0
In fact, you can also specify the output delimiters as well:
$ echo -n "1,2,3|4,5|6|7,8,9,0" | awk 'BEGIN{FS=","; RS="|";OFS="foo";ORS="bar"} {print NF, $0}'
3foo1,2,3bar2foo4,5bar1foo6bar4foo7,8,9,0bar
- groovy2shoes 13y agoYup. It wasn't fun to type (using Ctrl-V in bash to input the raw control characters), but it works fine with the ASCII separators as well: $ echo -n 'a^_1^^b^_2^^c^_3^^' |awk 'BEGIN{FS="^_"; RS="^^"} {print $1": "$2}' a: 1 b: 2 c: 3