New answers tagged

4

There's no need for any pipe: awk -v max=0 '{if($2>max){name=$1; max=$2}}END{print name}' file Note that this assumes that the largest numerical value in the file is positive and that there is at least one line with two fields in the file, where the second field is numerical.


2

sort -k2 -nr myfileName.txt | head -1


1

there's an interesting hack where you can format bash command with awk and push it to bash like so: awk '{ print "find " $1 " -exec ls {} \;" }' ./source_file | bash this will give you instant execution of commands such as: find /var -exec ls {} \; find /home/user1 -exec ls {} \; # and so on depending on the contents of the ./source_file ...


1

Use: awk 1 file1 file2 ... > outfile instead of cat file1 file2 ... > outfile The only problem is that unlike cat, awk will immediately exit with an error if it cannot open and read any of file1, file2, etc, instead of continuing with the rest of the files. If that's a problem, on most modern systems you can use grep '' as already suggested here + the ...


Top 50 recent answers are included