How to use WHILE loop to do processin in BASH

Closed
zet1972 Posts 1 Registration date Thursday November 26, 2009 Status Member Last seen November 26, 2009 - Nov 26, 2009 at 06:54 PM
jipicy Posts 40842 Registration date Wednesday August 27, 2003 Status Moderator Last seen August 10, 2020 - Nov 29, 2009 at 10:56 AM
Hello,

I am stuck with coding a solution. Here is what I am trying to do.
Input file looks like this:
Rock - Franz Ferdinand - single - Do You Want To - 3:55 - 235 secs
Rock - Ani DiFranco - Reprieve - Millenium Theater - 3:14 - 194 secs
Rock - Enter The Haggis - Soapbox Heroes - New Monthly Flavour - 3:23 - 203 secs

My WHILE loop is coded as below, but it's not working. It ended up printing every row, instead of the rows than meet the criteria $col6 -le $val1
typeset -i var1=1000

while IFS="-" read col1 col2 col3 col4 col5 col6
do
if $col6 -le $val1;then
awk -F"-" '{print $1" - "$2" - "$3" - "$4" - "$5}' >> print.out
fi
done < data.dat

Can someone please help?
Related:

1 response

jipicy Posts 40842 Registration date Wednesday August 27, 2003 Status Moderator Last seen August 10, 2020 17
Nov 29, 2009 at 10:56 AM
Hi,

[tmpfs]$ cat data.dat
Rock - Franz Ferdinand - single - Do You Want To - 3:55 - 235 secs
Rock - Ani DiFranco - Reprieve - Millenium Theater - 3:14 - 194 secs
Rock - Enter The Haggis - Soapbox Heroes - New Monthly Flavour - 3:23 - 203 secs

[tmpfs]$ awk  -F"-" 'split($6,tb," ") {if(tb[1] <= 200)  { print $1"-"$2"-"$3"-"$4"-"$5 }} ' data.dat
Rock - Ani DiFranco - Reprieve - Millenium Theater - 3:14

[tmpfs]$

;-))
0