Re: How to use "sed" to subtract a file from another file



Pawel Gancarz wrote:
James wrote:

Hi all,

Two text files: FileA and FileB: each line only contains a userid
(no spaces or any other special chars). FileA is a superset of FileB.
I want to remove those lines, which appears in FileB, from FileA.
I could write a couple of lines to do it, but I really want to learn
"sed",
so any sed guru could give a one-line sed to solve this?


How about learning "grep" first?
grep -vf FileB FileA

Yes, grep is most easy here.

It is almost impossible with sed.
sed stands for stream editor - its input is a stream or pipe.
It cannot determin which filename it currently works on,
nor it can read commands from a pipe.

If both files are sorted, comm is another solution:

sort -o FileA FileA
sort -o FileB FileB

comm -13 FileB FileA

--
Michael Tosch @ hp : com
.



Relevant Pages

  • Re: Wrong Publisher File Attached in Email?
    ... User opens fileA ... User edits fileB and saves it ... The "Sent" folder in Outlook is opened in order to check the email to ... If we go straight to Outlook after saving fileB, and manually attach fileB ...
    (microsoft.public.publisher)
  • Re: delete using sed and line number file ....
    ... If FileA and FileB are very ... sys 0m0.328s ...
    (comp.unix.shell)
  • Re: exchange some string in two files?
    ... exchange everyline of char 200-250 on FILEA with everyline of char ... Is there any corelation between FILEA and FILEB? ... there is no ovbious corelation between FILEA and FILEB. ...
    (comp.unix.shell)
  • Re: read-modify-write textfile problem
    ... Const ForReading = 1 ... Set fso = CreateObject ... fileB indeed contains the modified information. ... > I don't understand "when fileA and fileB are the same" ...
    (microsoft.public.frontpage.programming)
  • Re: Why does cp -r copy unsorted?
    ... > It just copy data from one directory to another, there is no reason ... > why entries in one directory have to be sorted in any specific way. ... > If you want them sorted, use a script that read the directory, sort ... done < fileA ...
    (comp.os.linux.misc)