f



HOW using 1 files contents as info to delete the second files containing that pattern?

Given 2 files

one file having a list of names
the other containing a list of names to delete from the first

use sed or diff or write a script?

problem is I don't know about file i/o in scripts yet I guess.


ie  using read command on a file reading the first line in the file,
then using next after the 2 lines are compaired and equal == must be
deleted.
read next line as the pattern, search untill found (records match
exactly) then delete, read next line in file as the pattern to search
until found.......again untill are are deleted.

How -I just have bits and pieces now..

Help and thank you for all you do ! really !
matt
0
Sputz
10/25/2003 8:07:26 PM
comp.unix.shell 15484 articles. 3 followers. Post Follow

5 Replies
579 Views

Similar Articles

[PageSpeed] 11

On Sat, 25 Oct 2003 20:07:26 GMT, Sputz Yadoo <Sputz@Daytona.com> wrote:
> 
> 
> Given 2 files
> 
> one file having a list of names

file1


> the other containing a list of names to delete from the first
> 

file2

------------------------
Here's one way to do it, Sputz:

#!/bin/sh

while read line; do
sed "/$line/d"  file1 > tempfile ; mv tmpfile file1
done < file2

exit 0



-- 
Alan C
Post validation at http://tinyurl.com/rv0y
0
Alan
10/25/2003 8:59:04 PM
In article <pq0mpvkdlod0b6u9g3p9422unfpi9hbk6h@4ax.com>,
Sputz Yadoo  <Sputz@Daytona.com> wrote:
>Given 2 files
>
>one file having a list of names
>the other containing a list of names to delete from the first
>
>use sed or diff or write a script?
>
>problem is I don't know about file i/o in scripts yet I guess.
>
>
>ie  using read command on a file reading the first line in the file,
>then using next after the 2 lines are compaired and equal == must be
>deleted.
>read next line as the pattern, search untill found (records match
>exactly) then delete, read next line in file as the pattern to search
>until found.......again untill are are deleted.
>
>How -I just have bits and pieces now..
>
>Help and thank you for all you do ! really !
>matt

sounds like a job for grep of fgrep

grep -v -f file2 file1
fgrep -v -f file2 file1

man grep
man fgrep


Chuck Demas

-- 
  Eat Healthy        |   _ _   | Nothing would be done at all,
  Stay Fit           |   @ @   | If a man waited to do it so well,
  Die Anyway         |    v    | That no one could find fault with it.
  demas@theworld.com |  \___/  | http://world.std.com/~cpd
0
demas
10/25/2003 10:32:56 PM
I get the following errors

sed: -e expression #1   char 9 : unknown command : `o'   #( that is
backslash -o-single quote)

On Sat, 25 Oct 2003 20:59:04 GMT, Alan Connor <zzzzzz@xxx.yyy> wrote:

>On Sat, 25 Oct 2003 20:07:26 GMT, Sputz Yadoo <Sputz@Daytona.com> wrote:
>> 
>> 
>> Given 2 files
>> 
>> one file having a list of names
>
>file1
>
>
>> the other containing a list of names to delete from the first
>> 
>
>file2
>
>------------------------
>Here's one way to do it, Sputz:
>
>#!/bin/sh
>
>while read line; do
>sed "/$line/d"  file1 > tempfile ; mv tmpfile file1
>done < file2
>
>exit 0

0
Sputz
10/25/2003 11:57:50 PM
On Sat, 25 Oct 2003 23:57:50 GMT, Sputz Yadoo <Sputz@Daytona.com> wrote:
> 
> 
> I get the following errors
> 
> sed: -e expression #1   char 9 : unknown command : `o'   #( that is
> backslash -o-single quote)
> 
> On Sat, 25 Oct 2003 20:59:04 GMT, Alan Connor <zzzzzz@xxx.yyy> wrote:
> 
>>On Sat, 25 Oct 2003 20:07:26 GMT, Sputz Yadoo <Sputz@Daytona.com> wrote:
>>> 
>>> 
>>> Given 2 files
>>> 
>>> one file having a list of names
>>
>>file1
>>
>>
>>> the other containing a list of names to delete from the first
>>> 
>>
>>file2
>>
>>------------------------
>>Here's one way to do it, Sputz:
>>
>>#!/bin/sh
>>
>>while read line; do
>>sed "/$line/d"  file1 > tempfile ; mv tmpfile file1
>>done < file2
>>
>>exit 0
> 


That's supposed to be a "d".  But there is a mistake in the script: it should
read ... > tempfile ; mv tempfile file1

But you should always  do a test run first. Piping the output to less works.


-- 
Alan C
Post validation at http://tinyurl.com/rv0y
0
Alan
10/26/2003 12:29:03 AM
Thanks Chuck
grep -v -f patternfile  listing > newlisting

Thats all it took !!
Your wizdom has learned me good

Thank you all so much !!
Matt 


On Sat, 25 Oct 2003 22:32:56 +0000 (UTC), demas@TheWorld.com (Charles
Demas) wrote:

>In article <pq0mpvkdlod0b6u9g3p9422unfpi9hbk6h@4ax.com>,
>Sputz Yadoo  <Sputz@Daytona.com> wrote:
>>Given 2 files
>>
>>one file having a list of names
>>the other containing a list of names to delete from the first
>>
>>use sed or diff or write a script?
>>
>>problem is I don't know about file i/o in scripts yet I guess.
>>
>>
>>ie  using read command on a file reading the first line in the file,
>>then using next after the 2 lines are compaired and equal == must be
>>deleted.
>>read next line as the pattern, search untill found (records match
>>exactly) then delete, read next line in file as the pattern to search
>>until found.......again untill are are deleted.
>>
>>How -I just have bits and pieces now..
>>
>>Help and thank you for all you do ! really !
>>matt
>
>sounds like a job for grep of fgrep
>
>grep -v -f file2 file1
>fgrep -v -f file2 file1
>
>man grep
>man fgrep
>
>
>Chuck Demas

0
Sputz
10/26/2003 7:20:32 PM
Reply: