Ok you wizards, how do i create a loop that repeats the awk part of this script.
I have a process that needs to be repeated between 80 and 100 times for each file, depending on the number of names in row 1.
Here's a sample of the input. Row one contains the date and names (comma delimited) (this example has only 2 names instead of 80 or 100. Rows >1 contain the date and data needed):
DATE,"VPR ""A"" #02","VPR ""A"" #03"
01-Jan-00,0,139.39
02-Jan-00,0,125.06
03-Jan-00,0,120.64
04-Jan-00,0,123.56
05-Jan-00,0,16.23
06-Jan-00,0,133.91
07-Jan-00,0,122.43
08-Jan-00,0,130.66
Here's the script so far:
I've written the sed part out to a file - it seemed faster.
The awk part of the script needs to pick up the name in row one, then print out that name, then the date in $1 and the data in the same column as the name.
I need a loop to repeat and append to a file, the NAME, DATE, GAS, and the newly created DayGas FOR EACH COLUMN.
------ script so far.-----
echo "NAME" "\t" "DATE" "\t" "GAS" "\t" "DayGas" > A.txt
sed '
s/",/,/g
s/,"/,/g
s/""/"/g' Agas.csv > agas.tmp
awk -F, '
$1 == "DATE" { NAME = $2 }
{ if ($1 ~ /DATE/ )
next
else
if ( $2 > 0 )
Day = 1
else
Day = 0
print NAME "\t" $1 "\t" $2"\t" Day }
' agas.tmp >> A.txt
------
If I were to create the next awk statement, it would be:
awk -F, '
$1 == "DATE" { NAME = $3 }
{ if ($1 ~ /DATE/ )
next
else
if ( $3 > 0 )
Day = 1
else
Day = 0
print NAME "\t" $1 "\t" $3"\t" Day }
' agas.tmp >> A.txt
I've tried... but I'd rather figure this out this than paste the awk part 80 to 100 times and edit. Although, I probably could have done that by now.
Thanks
I have a process that needs to be repeated between 80 and 100 times for each file, depending on the number of names in row 1.
Here's a sample of the input. Row one contains the date and names (comma delimited) (this example has only 2 names instead of 80 or 100. Rows >1 contain the date and data needed):
DATE,"VPR ""A"" #02","VPR ""A"" #03"
01-Jan-00,0,139.39
02-Jan-00,0,125.06
03-Jan-00,0,120.64
04-Jan-00,0,123.56
05-Jan-00,0,16.23
06-Jan-00,0,133.91
07-Jan-00,0,122.43
08-Jan-00,0,130.66
Here's the script so far:
I've written the sed part out to a file - it seemed faster.
The awk part of the script needs to pick up the name in row one, then print out that name, then the date in $1 and the data in the same column as the name.
I need a loop to repeat and append to a file, the NAME, DATE, GAS, and the newly created DayGas FOR EACH COLUMN.
------ script so far.-----
echo "NAME" "\t" "DATE" "\t" "GAS" "\t" "DayGas" > A.txt
sed '
s/",/,/g
s/,"/,/g
s/""/"/g' Agas.csv > agas.tmp
awk -F, '
$1 == "DATE" { NAME = $2 }
{ if ($1 ~ /DATE/ )
next
else
if ( $2 > 0 )
Day = 1
else
Day = 0
print NAME "\t" $1 "\t" $2"\t" Day }
' agas.tmp >> A.txt
------
If I were to create the next awk statement, it would be:
awk -F, '
$1 == "DATE" { NAME = $3 }
{ if ($1 ~ /DATE/ )
next
else
if ( $3 > 0 )
Day = 1
else
Day = 0
print NAME "\t" $1 "\t" $3"\t" Day }
' agas.tmp >> A.txt
I've tried... but I'd rather figure this out this than paste the awk part 80 to 100 times and edit. Although, I probably could have done that by now.
Thanks