unix - Substitute some patterns with skipping others -


my question how format file this:

name 2ndname surname 879654 name surname 546312 

to this:

name 2ndname,surname,879654 name,surname,546312 

as can see difficulty save space before name , 2ndname if sb have 2ndname. found command:

 sed -i 's/[[:space:]]/,/' file.txt 

but doesnt include possibility of leaving spaces alone.

given limited example, might someplace start:

awk 'nf == 4 {printf "%s %s,%s,%s\n",$1,$2,$3,$4} \      nf == 3 {printf "%s,%s,%s\n",$1,$2,$3} \      nf > 4 || nf < 3 {print "error!"}' file.txt 

Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -