LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 04-08-2011, 03:01 PM   #16
Eppo
Member
 
Registered: Feb 2007
Location: NY
Distribution: Arch, Ubuntu
Posts: 77

Original Poster
Rep: Reputation: 27

yes, exactly
 
Old 04-08-2011, 04:00 PM   #17
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Code:
awk 'BEGIN { FS="|" } { if (NF == 13) print $0"|"; else print; }'
 
Old 04-08-2011, 04:47 PM   #18
Eppo
Member
 
Registered: Feb 2007
Location: NY
Distribution: Arch, Ubuntu
Posts: 77

Original Poster
Rep: Reputation: 27
these were the original lines:
MSH| ~\&|ANTRIM|blah blah blah 33D0654120 CLIA|CDR|LMS|201009180440||ORU R01||D|2.3.1|
PID|1||0386132|0386132|Donald Duck ||19570210|M|U||

when i run the awk code i get this:
MSH| ~\&|ANTRIM|blah blah blah 33D0654120 CLIA|CDR|LMS|201009180440||ORU R01||D|2.3.1||
PID|1||0386132|0386132|Donald Duck||19570210|M|U||

it looks like its adding it to the line that starts with MSH instead
 
Old 04-08-2011, 04:56 PM   #19
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Change the code to:
Code:
awk 'BEGIN{ FS="|" } $1~/PID/ {if(NF == 13) print $0"|"; else print; }'
 
Old 04-09-2011, 02:50 AM   #20
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
Code:
awk -F"|" '/^PID/ && NF <= 13{$13=OFS="|"}1' file
 
  


Reply

Tags
od, sed, tr



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
sed or awk help sharky Programming 13 03-02-2010 05:17 PM
need help with sed/awk jbeiter Programming 7 02-26-2010 11:13 AM
Help with awk or sed. tuxtutorials Linux - Software 1 07-23-2009 02:45 AM
sed or awk ilo Programming 1 08-22-2008 10:38 AM
Sed and Awk Gins Programming 7 04-19-2006 10:32 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:47 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration