Bash sort ignores the first 5 lines

I am having trouble ignoring the first 5 lines of my file while sorting the rest. My current command sorts the entire file by the second element, however I need to skip the first 5 lines of the header. I need to read it and write to the same file.

Current team

sort -f -t $ -k2n,2 -o /folder/File.txt /folder/File.txt

Example

2016/07/07 15:41:02
@24921
@
@
@-1
b$1$4$...
a$2$5$...
+4
source share
2 answers

This sorts lines 6 and after the file, leaving the first 5 lines unchanged:

{ head -n5 file.txt; tail -n+6 file.txt | sort -ft$ -k2n,2; } >file.tmp && mv file.tmp file.txt

Tcsh

Unlike bash, kshand zsh, tcshdoes not support grouping commands with {...}. Instead, try a subshell:

( head -n5 file.txt; tail -n+6 file.txt | sort -ft$ -k2n,2 ) >file.tmp && mv file.tmp file.txt
+6
source

Decision:

  • , - , head.tmp tail.tmp.
  • tail.tmp head.tmp .

:

$ sed -n -e '1,5w head.tmp' -e '6,$w tail.tmp' data.in
$ sort tail.tmp | cat head.tmp - >data.new
+1

All Articles