Computing.Net > Forums > Unix > SED changes by columns

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

SED changes by columns

Reply to Message Icon

Name: braveking
Date: February 3, 2004 at 09:03:39 Pacific
OS: Solaris
CPU/Ram: 512
Comment:

Is there an easy way to tell sed command to make changes only in certain columns?

For example, if my input is
121| 3| apple |
312| 005| |

The output should be
121|3| apple |
312|005| |

In other words, i only want to change spaces in column 2.

My code currently replacing spaces in all instances.
sed -e 's/ //g' inputfile




Sponsored Link
Ads by Google

Response Number 1
Name: James Boothe
Date: February 3, 2004 at 11:33:33 Pacific
Reply:

You might could do that with a complex regexp, but I don't think that would qualify as an easy way.

But it is very easy with awk:

awk -F\| '\
BEGIN {OFS="|"}
 {gsub(" ","",$2)
  print}
' myinput


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: SED changes by columns

sed command www.computing.net/answers/unix/sed-command/3830.html

sed help with variable length file www.computing.net/answers/unix/sed-help-with-variable-length-file/5632.html

arrayed arrays !! www.computing.net/answers/unix/arrayed-arrays-/4507.html