Use "cat" to merge multiple files
|
|
|
Comments (7)
If those files are really, really big, you can do:
cat file1 file2 file 3 | uniq | sort | uniq > sorted_file_no_dupes
to strip out the dupes before sorting.
cat file1 file2 file 3 | uniq | sort | uniq > sorted_file_no_dupes
to strip out the dupes before sorting.
What blew my mind was how often that works for video files.
What blew my mind is how little it takes to be published on LXer. Apparently, I can start a blog, write an entry stating:
Is The Linux Desktop Dead?
The term command to list files is ls.
Example:
$ ls /dir_name
Who knew! ;)
nb
Is The Linux Desktop Dead?
The term command to list files is ls.
Example:
$ ls /dir_name
Who knew! ;)
nb
Quoting:What blew my mind is how little it takes to be published on LXer.
Yes it's great isn't it.
@gus3 --
Careful with that...
That first uniq is only going to get the dupes that can be found without sorting. You're as likely to increase your overall execution time as to decrease it. Maybe moreso, depending on the size of the files and how sorted they are or are not.
Careful with that...
That first uniq is only going to get the dupes that can be found without sorting. You're as likely to increase your overall execution time as to decrease it. Maybe moreso, depending on the size of the files and how sorted they are or are not.
Wait till you give an example with xargs in an interview. That floors people every time.
P.S.: xargs is your friend.
P.S.: xargs is your friend.
Post a comment
A free account is needed to post. Write your comment here first: your text is kept in this browser while you sign up or log in, and is waiting for you when you come back.
Your message:Markdown: **bold**, *italic*, [text](https://link), - lists, > quotes, $x^2$ for math. Formatting help
Sign up and post (it is free) or Log in and post

So ...
cat file1 file2 file3 | sort > sorted_file
cat file1 file2 file 3 | sort | uniq > sorted_file_no_dupes
And we haven't even tried to do any sed or awk magic.