I'm having trouble ignoring the first 5 lines of my file while sorting the rest. My current command sorts the entire file by the second item, however I need to skip the first 5 "header" lines. I need read it and write it to the same file.
Current Command
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$...
This sorts lines 6 and after of the file while 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
Unlike bash
, ksh
, and zsh
, tcsh
does not support command grouping 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
Solution:
head.tmp
and tail.tmp
. tail.tmp
and concatenate head.tmp
with the sorted result.At the prompt:
$ sed -n -e '1,5w head.tmp' -e '6,$w tail.tmp' data.in
$ sort tail.tmp | cat head.tmp - >data.new
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With