Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
I need to combine 2 files. Requirement is - if the last line of file 1 starts with '99' replace that line with the data ( line 2 through end of the file) in file 2.
File 1 looks like:
01asdlkjalskjasldfjalskjfd
02lkjdslkjlkajsljljas
03lkjdslkjljlsajdla
.
.
.
99ljlsdjljasldjlsajdFile 2 looks like:
01asdlkjalskjasldfjalskjfd
02lkjdslkjlkajsljljas
03lkjdslkjljlsajdla
.
.
.
99ljlsdjljasldjlsajdThe output should look like :
01asdlkjalskjasldfjalskjfd
02lkjdslkjlkajsljljas
03lkjdslkjljlsajdla
02lkjdslkjlkajsljljas
03lkjdslkjljlsajdla
99ljlsdjljasldjlsajdWhich means, there should be only one '01' record and '99' record in the output file.
Could someone helpme out with this?
Thanks in advance.
-Osho

This should work, results are stored in a file called combined. I used the file names tfile1 and tfile2 for your File 1 and File 2:
#!/usr/bin/ksh
nnol=$(tail -1 tfile1|grep ^99)
if [[ $nnol != "" ]];then
grep -v $nnol tfile1 > combined
tail +2 tfile2 >> combined
fi

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |