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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SED Help 1

Status
Not open for further replies.

alan147

Technical User
Nov 15, 2002
128
GB
Good morning

I have a file that is used as the input to expect, it contains commands to sftp files from a remote server and a list of files to get. I would like to check the input file against a list of previously downloaded files so that any that we have already downloaded are removed from the input list. The input file looks like this:

cd /path to files
get filename1
get filename2
cd /path to files/sub directory1
lcd /local path to files/sub directory 1
get filename 3
get filename 4
cd /path to files/sub directory2
lcd /local path to files/sub directory 2
get filename 5

the list of downloaded files looks like this

filename 2
filename 4

What I want to do is delete filename 2 and filename 4
from the input file.

I have tried a for loop reading the downloaded list then passing it through sed

for file_name in `cat downloaded_list`
do
cat input_file | sed "/$file_name/ d" > new_input_file
done

I have also tried grep -EV

neither of which have worked.

Any ideas?

Thanks

Alan
 
Hi

I will consider 'filename2' vs 'filename 2' a typo.
Alan said:
I have also tried grep -EV
Better approach then [tt]sed[/tt]. Try this :
Code:
grep -v -f alreadydownloaded.txt ftpcommand.txt > remainingftpcommand.txt

[gray]# or if your grep supports -F ( --fixed-strings )[/gray]

grep -v -F -f alreadydownloaded.txt ftpcommand.txt > remainingftpcommand.txt
Tested with GNU [tt]grep[/tt].

Feherke.
 
Brilliant. Thanks very much, I'd been trying for a couple of days to sort it out.

Alan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top