LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 11-03-2004, 07:18 AM   #1
iluvatar
Member
 
Registered: Jul 2003
Location: netherlands
Distribution: debian
Posts: 403

Rep: Reputation: 30
awk script forgets tabs


I have the following awk command:

awk -F"\t" '$1=="ART" && $2=="49011000" {$2="49111090";$6="00"}; {print $0}' test

the file is tab seperated, when the 1st field is "ART" and the 2nd field is "49011000" then the 2nd and the 6th field are changed. works great, except that the output lines wich are changed don't have the tabs anymore, those are replaced with spaces... the unaffected lines come through with all tabs correct. anyone knows why and how to solve this?

thanx in advance,
.-=~ iluvatar ~=-.
 
Old 11-03-2004, 11:24 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373
Hi,

The moment you start 'editing' the content of the fields, the standard output field seperator (OFS) is used, which is a space. That explains why unchanged lines have tabs and changed lines don't.

Best way to tackle this: Set the OFS value to a tab:

awk -F"\t" 'BEGIN { OFS="\t" } $1=="ART" && $2=="49011000" {$2="49111090";$6="00"}; {print $0}' test

Hope this helps.
 
Old 11-04-2004, 01:56 AM   #3
iluvatar
Member
 
Registered: Jul 2003
Location: netherlands
Distribution: debian
Posts: 403

Original Poster
Rep: Reputation: 30
ah that explains a lot thanks!

greetz,
.-=~ iluvatar ~=-.
 
  


Reply

Tags
awk


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
About awk script sachin_keluskar Linux - Software 2 06-24-2005 03:19 AM
AWK script is hanging our server Hans Zarkoff Programming 10 08-20-2004 01:32 PM
opening new bash tabs or consoles from a script Nice-n-Slow Programming 7 07-12-2004 09:25 AM
Passing variables from AWK script to my shell script BigLarry Programming 1 06-12-2004 04:32 AM
How do I run an awk script? davee Programming 2 08-12-2003 08:46 AM


All times are GMT -5. The time now is 02:26 PM.

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