Probably this is a very basic question for shell programmers. But suppose I have a text file A and B and B is a subset of A.
I want to create a text file C which contains (A-B) data.
So omit all the common lines .
The line in files are numeric data: like
id , some aspect, other aspec.
Thanks.
Working with command line shell is bit difficult for the beginners because it's hard to memorize so many commands. It is very powerful, it allows user to store commands in a file and execute them together.
Your interface to the operating system is called a shell. The shell is the outermost layer of the operating system. Shells incorporate a programming language to control processes and files, as well as to start and control other programs.
Use sort
and uniq
sort a b | uniq -u
If you want the lines that are the same between A and B, you can use uniq -d
sort a b | uniq -d
This assumes of course that the data in A and B are exactly the same. There cannot be any lose spaces or tabs in the datasets. If there are, you'll have to clean up the data with sed
, tr
, or awk
first.
Edit
As Peter. O pointed out, this will fail if there happen to be exact duplicates in file a
. If that's an issue, you can fix it by doing this:
sort <(sort -u a) b | uniq -u
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With