Computing.Net > Forums > Unix > Removing spaces added by awk

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.

Removing spaces added by awk

Reply to Message Icon

Name: pnbalaji
Date: March 19, 2008 at 15:14:23 Pacific
OS: AIX 5.3
CPU/Ram: 8GB
Product: IBM, 7026-H80
Comment:

Hi,

I have a file f1 that contains the below line in it.

/logo/jpg/CustArtRepository/04/04/0492304_CA001_300.jpg

I am using the below awk command to extract 04/04 from it.
awk -F"/" '{print $5,"/",$6}' f1 > f2

However, awk is printing it as "04 / 04". I want it as 04/04 (not with the spaces in it).

Can some one help me?

Thanks,
Balaji.



Sponsored Link
Ads by Google

Response Number 1
Name: James Boothe
Date: March 19, 2008 at 15:52:32 Pacific
Reply:

Each comma in your print command is causing awk to insert a space at that position.

Actually, awk inserts the current value of the Output Field Separator (OFS), which by default is set to a space.

So what you want is:

awk -F"/" '{print $5 "/" $6}' f1 > f2


0

Response Number 2
Name: pnbalaji
Date: March 20, 2008 at 09:37:30 Pacific
Reply:

Thanks. It works perfectly.

Thanks,
Balaji.


0

Sponsored Link
Ads by Google
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: Removing spaces added by awk

remove spaces www.computing.net/answers/unix/remove-spaces/4398.html

How to remove a record by ID www.computing.net/answers/unix/how-to-remove-a-record-by-id/7635.html

How to remove spaces in filenames www.computing.net/answers/unix/how-to-remove-spaces-in-filenames/8204.html