LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-09-2009, 12:16 PM   #1
tmcguinness
LQ Newbie
 
Registered: Dec 2008
Posts: 11

Rep: Reputation: 0
how to keep Field Separator in AWK when using a sub statement


Ok so here is my little one liner:

cat somefile.txt | awk -F\| '{ sub(//,"999",$3); print }'

The delimiter is a | and the results end up without anything but spaces which ruins my output.

I know there is a fairly easy way to avoid this - anyone?
 
Old 02-09-2009, 02:09 PM   #2
jan61
Member
 
Registered: Jun 2008
Posts: 235

Rep: Reputation: 46
Moin,

Code:
awk -F\| 'BEGIN {OFS="|"}{ sub(//,"999",$3); print }' somefile.txt
Jan

P.S.: Please - no useless use of cat award parties here ;-)
 
Old 02-09-2009, 02:16 PM   #3
tmcguinness
LQ Newbie
 
Registered: Dec 2008
Posts: 11

Original Poster
Rep: Reputation: 0
Gruetzi!

Ah - yes - thanks I thought it was something similar to setting OFS!

Cheers,
todd
 
Old 02-09-2009, 02:19 PM   #4
tmcguinness
LQ Newbie
 
Registered: Dec 2008
Posts: 11

Original Poster
Rep: Reputation: 0
Oh and the reason I was using a cat was due to the data actually being piped into the statement. It was really for simplicity.
 
Old 02-09-2009, 02:24 PM   #5
jan61
Member
 
Registered: Jun 2008
Posts: 235

Rep: Reputation: 46
Moin,

Quote:
Originally Posted by tmcguinness View Post
Oh and the reason I was using a cat was due to the data actually being piped into the statement. It was really for simplicity.
oh - in this case I can live with it and won't receive any nightmares tonight ;-)

Jan
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
deleting a field using awk jkeertir Linux - Newbie 5 04-13-2008 10:55 PM
awk record separator question johnpaulodonnell Linux - Newbie 2 07-30-2007 09:35 AM
perl input field separator Tinkster Programming 5 10-18-2004 04:08 PM
My field separator changes when using awk Helene Programming 3 05-01-2004 08:10 AM
Two field seperators in awk?? Astro Programming 2 11-09-2003 10:12 AM


All times are GMT -5. The time now is 09:51 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration