LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713
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: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,974
Blog Entries: 11

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
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
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,485

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


Reply

Tags
od, sed, tr


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
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


All times are GMT -5. The time now is 06:43 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