shell - Use awk/sed to delete everything after and including third comma on each line -
i have file lines one:
a, b, c, d, e from that, obtain:
a, b, c can use sed or awk this?
yes, can:
sed -r 's/([^,]+,)([^,]+,)([^,]+).*/\1\2\3/' if want keep more 3 fields, along these lines might better:
sed -r 's/(([^,]+,){2}([^,]+)).*/\1/' with awk, do:
awk -v ofs=',' -f, '{nf=3; print}'
Comments
Post a Comment