Ordering lines of a file numerically Linux/Unix -


i have 2 files compare. 1 file orders numbers

1    somedata  otherdata 2    somedata  otherdata 3    somedata  otherdata 4    somedata  otherdata 5    somedata  otherdata 6    somedata  otherdata 7    somedata  otherdata 8    somedata  otherdata y    somedata  otherdata y    somedata  otherdata 

the other orders

1    somedata  otherdata 10    somedata  otherdata 11    somedata  otherdata 12    somedata  otherdata . . . 2    somedata  otherdata y   somedata  otherdata y   somedata  otherdata 

it make life infinitely easier if sort second file (because first file has header keep in place. each line of header begins #.) before run it, comparing apples apples.

i have tried: sort -n /home/me/file.txt -o /home/me/newfile.txt

and want put letters @ top instead of bottom. this:

    y    somedata  otherdata     y    somedata  otherdata     1    somedata  otherdata     2    somedata  otherdata     3    somedata  otherdata     4    somedata  otherdata     5    somedata  otherdata     6    somedata  otherdata     7    somedata  otherdata     8    somedata  otherdata 

what sort numerically end letters @ bottom? or, failing that, there way exclude lines, perhaps, begin character?

you can pull out header lines before running sort, add them in after. if have $n lines of header, following pipe out after it:

head -n $n filewithheader.txt >newfile.txt tail -n $((cat filewithheader.txt| wc -l -$n)) | sort -n >>newfile.txt 

now can sort files same.

if really want sort alphabetically numerically, i'd grep grab lines begin text 1 file, grep lines begin numbers second file, sort them separately, combine. hope helps.


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -