I use the following AWK command to sort the contents after the first 24 lines of a file:
awk 'NR <= 24; NR > 24 {print $0 | "sort -k3,3 -k4,4n"}' file > newFile
Now I want to join two files first (now simply discard the first 24 lines for both files) and then sort the merged file. Is there any way to do it without generating a temporary merged file?
NR <= 24;
is redundant; simply filtering withNR > 24
would only print the records you want. – Jonathan Lefflerawk 'NR > 24 {"sort -k3,3 -k4,4n"}'
doesn't work at all? Seems that I have to include the first command (print $0) and "|" even when I don't need to print out the first 24 lines. @JonathanLeffler – Runner{"sort..."}
notation simply lists a string literal as 'the action'. There's no I/O redirection; noprint
; no assignment; no anything active -- so the statement is a no-op and the whole script is a no-op (the lines less than 25 are ignored and the lines greater than 24 are no-opped (is that a word? I guess it is, now), so the net result is the same as 'cat > /dev/null'. – Jonathan Leffler