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
Post a Comment