Reputation: 89
I am using bash scripting in Linux. I have a variable that looks like this:
a="1-1-1 1-1-2 1-1-3 1-1-4"
I want to separate columns with values equal to or greater than 1-1-3 using AWK.
My output should be:
1-1-3 1-1-4
Can someone help me with this?
Upvotes: 1
Views: 105
Reputation: 246807
sort's -V
option gives you "version" sorting that might be helpful:
$ a="2-0-0 1-1-1 1-1-2 1-1-3 1-1-4"
$ tr ' ' '\n' <<<"$a" | sort -V
1-1-1
1-1-2
1-1-3
1-1-4
2-0-0
Upvotes: 1
Reputation: 89557
You can do it without a loop, if you use the space as record separator:
echo $a | awk -v RS=' ' -v ORS=' ' '{$1=$1} $1>="1-1-3"'
Upvotes: 1
Reputation: 121387
You can loop over the line and compare:
echo $a | awk -v ORS=' ' '{for(i=1;i<=NF;i++) if($i >= "1-1-3") print $i;}'
Upvotes: 1