I want to put the result of the sort method into an array where each cell contains a word. I tried this code but only part of the $file is printed and its not sorted:
#!/bin/bash
for file in `ls ${1}` ; do
if [[ ! ($file = *.user) ]] ; then
continue
fi
arr=(`sort -nrk4 $file`)
echo ${arr[*]}
done
Why isnt this working? How can I do this?
Data file:
name1 01/01/1994 a 0
name2 01/01/1994 b 5
name3 01/01/1994 c 2
If I run the sort line only (sort -nrk4 $file), this is whats printed:
name2 01/01/1994 b 5
name3 01/01/1994 c 2
name1 01/01/1994 a 0
When I run the 2 lines above, this is what its printed:
name1 01/01/1994 a 0