I have a list of data that I need to analyze. The first thing I do is check whether the file is indeed the one I want, then I sort the data according to the 4th column, and then I need to manually order the sorted line.
For example, I need to print the 3rd word in the line, and then the first word etc.
Here is what I wrote:
mainScript :
#!/bin/bash
for file in `ls ${1}` ; do
if [[ ! ($file = *.user) ]] ; then
continue
fi
sort -nrk4 $file | source printer_script
done
printer_script :
#!/bin/bash
echo $3
echo $1
echo $2
Why nothing gets printed even though I send the sorted lines by pipeline?
Because with the pipe the output of sort goes to the standard input of your script, and in it instead you are looking at the parameters; if you want to grab that output and pass it as parameters, you should do: