Results 1 to 3 of 3
Hi, i have 2 files:
test0.txt
555-2397 Beckett, Barry
555-5116 Carter, Gertrude
555-7929 Jones, Theresa
555-9871 Orwell, Samuel
test2.txt
555-9871 unlisted
555-5116 listed
555-2397 unlisted
555-7929 listed
before using the ...
- 04-29-2010 #1Just Joined!
- Join Date
- Apr 2010
- Posts
- 2
using join + sort
Hi, i have 2 files:
test0.txt
555-2397 Beckett, Barry
555-5116 Carter, Gertrude
555-7929 Jones, Theresa
555-9871 Orwell, Samuel
test2.txt
555-9871 unlisted
555-5116 listed
555-2397 unlisted
555-7929 listed
before using the join command i need to sort the test2.txt content, so:
it doesn't workCode:join test0.txt `sort -d test2.txt`
- 04-29-2010 #2
`sort -d test2.txt` will get replaced by Bash with the output of the sort command. But join is expecting two filenames.
Fortunately, join expects that maybe you'll want to pass in output from another program, and provides a facility to do this. We can do what you want by running the command:
What happens here? First, we run "sort -d test2.txt". We then pipe its output into our join command. Piping means that the output of one command becomes the input of another command.Code:sort -d test2.txt | join test0.txt -
The join command joins test0.txt with a special file "-". "-" tells join to read its standard input as the second file, not to use an actual file.
And this should work! Does it make sense to you?DISTRO=Arch
Registered Linux User #388732
- 04-30-2010 #3Just Joined!
- Join Date
- Apr 2010
- Posts
- 2
yes, it works, thanks for your explanation.
"-" mean it use its input from a pipe as file.


Reply With Quote