Computing.Net > Forums > Unix > Combining 2 files

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.

Combining 2 files

Reply to Message Icon

Name: osho64
Date: March 4, 2008 at 01:18:22 Pacific
OS: HP-UX
CPU/Ram: Unkown
Product: HP
Comment:

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
.
.
.
99ljlsdjljasldjlsajd

File 2 looks like:
01asdlkjalskjasldfjalskjfd
02lkjdslkjlkajsljljas
03lkjdslkjljlsajdla
.
.
.
99ljlsdjljasldjlsajd

The output should look like :

01asdlkjalskjasldfjalskjfd
02lkjdslkjlkajsljljas
03lkjdslkjljlsajdla
02lkjdslkjlkajsljljas
03lkjdslkjljlsajdla
99ljlsdjljasldjlsajd

Which 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



Sponsored Link
Ads by Google

Response Number 1
Name: lankrypt0
Date: March 4, 2008 at 06:51:37 Pacific
Reply:

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


0
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Combining 2 files

nawk combining multiple files www.computing.net/answers/unix/nawk-combining-multiple-files/5100.html

Combining files line by line www.computing.net/answers/unix/combining-files-line-by-line/7632.html

Concatenating 2 files www.computing.net/answers/unix/concatenating-2-files/1243.html