here is the code, the CN part is working but awk...
I run function outside and it seems really clear. I just meet the bash :(
windowsearch()
{
starting_line_number=$1
ending_line_number=$2
position=$3
file_name=$4
CN=$(head -40 $4 | sed -n "$1,$2p" )
awk -v CN=$CN -F "\t" '{ print $CN }' $4 | sort -n -k$3
}
windowsearch 10 20 2 $imdbdir/tsv2/title.principals.tsv
CodePudding user response:
My interpretation of your intention
you want to sort a range of lines from a file based on a given column.
$ awk -v start=10 -v end=20 'start<=NR && NR<=end' | sort -n k2
just parametrize input values in your script
CodePudding user response:
Your question lacks a description of the task and, ideally, examples of input data and desired output. It is hard to guess someone’s intentions from a completely broken script snippet. A possible wild guess might be:
windowsearch() {
awk "NR > ${2} {exit}
NR >= ${1}" < "$4" | sort -k "$3"
}
Example (sort /etc/fstab
lines 9 through 13 by mount point (field 2)):
windowsearch 9 13 2 /etc/fstab