How to sort files in command line and join them?



How do you sort files in command line and join them together to gather info required for analysis?


Try sort command. It depends upon what are you trying to sort. The syntax is:

sort file
sort [option] file

File can be joined together again depend upon your needs. Simple append can be done with cat command:

cat file1 file2 file3 > out

Use paste command to merge lines of files. Maybe you can provide some more info including sample data.


sample data AND expected corresponding result


cat * | sort -o MYDATA

if you want just to sort per file then put them all in one file;
( ls * |xargs -i sort {} )>MYDATA


what’s your email? I’m hoping to send you some files and show you what I’m having trouble with unless your busy?


when you ask questions to a forum everything has to be visible to everyone.


You can upload images and other files or just paste sample data.


but please, don’t post screenshot of the terminal, do a copy/paste.