Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem file 1

Status
Not open for further replies.

beaster

Technical User
Aug 20, 2001
225
US
I have a file that is a .csv Excel file which I download and ftp over to my unix OSS system every Friday at 4:45 pm. When I cat it in unix it reads the file and the output is below:

B00227C,7.0,5.6,65.9,5,30,97.9,78.2,98
B00229C,7.0,5.8,79.9,5,30,97.9,78.2,98
B00237C,6.5,5.6,79.9,5,30,97.9,78.2,98

I need it to compare fields $2 and $3 (if 2 and 3 are not equal then only print fields $1 through $5 to another file)

I want the output to look like:
It reflects the first and 2nd line above^. The output needs to be set so that the line where the % Avail is the lowest is at the top and so on.


Cell Id Avg Def Avg Avail %Avail Total Incoming
B00227C 7.0 5.6 65.9 5
B00229C 7.0 5.8 79.9 5

And so on for the lines that match the pattern. Thanks again for any help you can give!
Beaster


 
This may get you started.

BEGIN{FS=","}
{
if ($2 != $3) printf("%s %7.1f %7.1f %7.1f %7.1f\n",
$1, $2, $3, $4, $5)
}

In line 3 of your example data, field 2 (6.5) and field 3 (5.6) are unequal, so line 3 prints. You can pipe the output through sort to order the line based on % avail.

Hope this helps.

CaKiwi
 
I hope someone can see what I am doing wrong, I tried this above like this: In the fgrep I am just getting rid of some garbage. That is working fine.

fgrep -v -f /home/beaster/weekly_reports/top_cell_strip bh1bsc1_cell_top_five > beaster1
echo "Site Issues on BH1BSC1" >> beaster1

awk { FS = "," }
{ if ($2 != $3) printf("%s %7.1f %7.1f %7.1f %7.1f\n",
$1, $2, $3, $4, $5)
}' b1bsc1_cell_top_five >> beaster1


AND THIS IS WHAT I GET AS A RESPONSE:

awk: syntax error near line 1
awk: illegal statement near line 1
weekly_reports.sh: syntax error at line 648: `printf' unexpected
 
awk ' BEGIN { FS = " }
{
if ($2 != $3) {
printf "cakiwi's code here"
}
}' yourfile >> outputfile
 
It now finally works! i have one question though, if I want it to sort the output by field $4 what should I add to the input? It now looks like this.....Thanks for all the help!

awk " BEGIN { FS = "," }
{
if ($2 != $3)
{printf ("%s %7.1f %7.1f %7.1f %7.1f \n",
$1, $2, $3, $4, $5)
}
} \' beaster1 >> beaster2


 
Pipe the output from awk through sort.

awk '{...}' beaster1 | sort +3b >> beaster2

will sort on the 4th field (field 3 zero relative).

Hope this helps.

CaKiwi
 
I did a man on sort and discovered that my syntax is obsolete. Use vgersh99's syntax.

CaKiwi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top