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?
Many thanks,
James
How about learning "grep" first?
grep -vf FileB FileA
--
pgancarz, at, o2, pl
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
--
petribar:
Any sun-bleached prehistoric candy that has been sitting in
the window of a vending machine too long.
-- Rich Hall, "Sniglets"
That doesn't answer the question.
grep -Fxvf fileB fileA
would have.
--
Stéphane
You will get an excellent return on time spent if you
Read the O'Reilly book _sed & awk_ by Dale Dougherty.
--
Using OpenBSD with or without X & KDE?
See Dave's OpenBSD | X | KDE corner at
http://dfeustel.home.mindspring.com !!!
You say you want to subtract one file from another. Convert both files
to arrays and then use the "-" operator.
ruby -e 'puts gets(nil).to_a - gets(nil).to_a' FileA FileB
You'll get a strong hint on how to accomplish this in sed here:
http://
groups.google.com/group/comp.unix.questions/msg/7444d3fb518c70a3?hl=en&
As a one-liner? Hmmm, it's going to be one awfully long line.
The problem this method has with sed are metacharacters, e.g., if your
data contains a 5-character line such as "x\y\z" the method I illustrate
will endeavour to delete a 3-character line matching /^xyz$/, and so on.
Pre-processing the entire data file is the only way to get around this.
--
John Savage (my news address is not valid for email)
Using your (nice) hint I'd propose this form, quite short
but is it a sed one liner as it uses a pipe ?-) :
$ sed 's/^.*$/\/&\/d/' FileB | sed -f - FileA
Sample test :
$ seq 15 >MISCFILES/listA
$ cat MISCFILES/listB
3
7
10
12
$ sed 's/^.*$/\/&\/d/' MISCFILES/listB | sed -f - MISCFILES/listA
1
2
4
5
6
8
9
11
14
15