Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Urgent: check and Append text in a script 1

Status
Not open for further replies.

nani3456

Vendor
Feb 4, 2004
56
0
0
US
Hi Friends,

Can you please help me a writting a script.

File1 has the following text:
0 0,12 * * * /home/app/cr_colat/cdtdev/bin/SendNoti.sh -c

File2 has the following text
0 0,12 * * * /home/app/cr_colat/cdtdev/bin/SendNoti.sh -c
6 0,12 * * * /home/app/cr_colat/cdtdev/bin/SendNoti.sh -c

I want file1 to append to file2 if and only if file1 text is not already present in file2 ( file1 has to check file2 and if the file1's text not available in file2 it has to append to file2)

Please help
 
Does your grep support -f (check man grep?

Perhaps this will do the trick:

[tt]grep -xf File1 File2 || cat File1 >> File2[/tt]

Basically it searches for the contents of File1 in File2, only matching whole lines (-x), and if it fails to match it appens File1 to File2.

Annihilannic.
 
Hi Annihilannic,

The command you gave is appending file1 to file2 even when it run for second time, I doesn't want like that, when it runs for the second time it has to check in file2 for file1 text if and only if it is not present than append otherwise leave like that. Please help
 
Apologies, it is because of the '*' in the file I believe. Please try with fgrep instead.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top