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

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -