Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
insert lines from a file to diff fi
Name: Pradeepa Date: November 14, 2008 at 02:43:23 Pacific OS: UNIX CPU/Ram: 1GB
Comment:
Hi,
I have a file with a HDR, some lines (number of lines can vary) and a TRL. And this set is repeating. I have to insert 2 lines just after the TRL, but not after the last TRL. I was able to do it using SED, But as the business system does not support the SED, I have to rewrite the script. and the system supports awk. Please help.
The file is like, HDR --- --- --- TRL HDR --- --- TRL and expected is
HDR --- --- --- TRL 1st line 2nd line HDR ---- ---- TRL
Name: nails Date: November 14, 2008 at 08:55:59 Pacific
Reply:
This uses just the korn shell:
#!/bin/ksh
cnt=$(wc -l < datafile) echo $cnt ncnt=0 while read line do ((ncnt+=1)) echo "$line" if [[ "$line" = "TRL" && $ncnt -ne $cnt ]] then echo "line 1" echo "line 2" fi done < datafile > newdatafile
0
Response Number 2
Name: Pradeepa Date: November 18, 2008 at 00:57:48 Pacific
Reply:
Hi nails, thanks a lot for the solution. I have one more problem here which i did not mention. There will be more text after TRL, like "TRL 00 123 1235" i have to check it the line starts with "TRL and then do the rest. I tried using ^TRL, /^TRL/, it did not work. Please help me.
Thanks a lot Pradeepa
0
Response Number 3
Name: nails Date: November 18, 2008 at 08:58:24 Pacific
Reply:
How about trying the case statement:
#!/bin/ksh
cnt=$(wc -l < data2) echo $cnt ncnt=0 while read line do ((ncnt+=1)) echo "$line" case "$line" in TRL*) if [[ $ncnt -ne $cnt ]] then echo "line 1" echo "line 2" fi ;; esac done < datafile
0
Response Number 4
Name: Pradeepa Date: November 20, 2008 at 22:27:09 Pacific
Reply:
hey nails,
thanks a lot, It works.
0
Response Number 5
Name: Pradeepa Date: December 4, 2008 at 02:15:34 Pacific
Reply:
Hey,
when I do an echo the trailing tab spaces are removed, for example when i have the text "This is Testing tab <tabspace> " Could not press a tab.... When I do an echo of this, the tabspace is removed. Please help me as i want this tabspace after this.
Summary: Hi All, I want to get the first line from a file and write it into another file. Please help. Thanks in advance. Regards, Raj Thanks & Regards, Raj...
Summary: I was wondering if you could help me with a script to remove ALL the lines in a file that contain the word "BOUNDARY". I have the script like this so far, but It will only remove the first occurance ...
Summary: i hv written a shell script which exports data to a file and i want to filter out one particular line from that file and manipulate that line further. ...