LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   sed/awk help (https://www.linuxquestions.org/questions/programming-9/sed-awk-help-873651/)

Eppo 04-08-2011 03:01 PM

yes, exactly

MTK358 04-08-2011 04:00 PM

Code:

awk 'BEGIN { FS="|" } { if (NF == 13) print $0"|"; else print; }'

Eppo 04-08-2011 04:47 PM

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

Tinkster 04-08-2011 04:56 PM

Change the code to:
Code:

awk 'BEGIN{ FS="|" } $1~/PID/ {if(NF == 13) print $0"|"; else print; }'

grail 04-09-2011 02:50 AM

Code:

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


All times are GMT -5. The time now is 11:25 AM.