I have a report that I'd like to print columns headers on. The code appears as follows:
I am trying to make it print a report with column headers and am really shaky with the BEGIN statement:
When I attempt to print this report what I get are nice columns but no report! I have tried to search on different sites but many give horizontal row headers and I am unable to find what to do next.
Awk gurus? If you could help.. greatly appreciated!
Good to see someone trying to learn awk, a powerful and useful language, though a bit strange until you learn the assumptions behind it.
All of the code needs to be inside the same ' ' block. By putting the next statement into a separate ' ' block you are telling awk that it's a filename.
Whenever you find yourself doing awk | awk | awk, you should probably stop and think how it can be done in one awk. (Usually but not always.)
What does your input look like? You've posted your output.. I think..
Last edited by Corona688; 10-22-2013 at 01:34 PM..
Your BEGIN statement is fine, but, as Corona688 says, continue the script in the same '...' block.
But, what are you doing there? In the first script, you are printing absolute values of fields, even if you know they're text strings. Not an error, but pointless. In the second script, all you do is formatting the output to some extreme wide, space padded columns. Not an error, but pointless if you pipe that to the next awk, which uses any number of spaces as field separator, so your formatting is gone. Plus, you again calculate absolute values, knowing that all numbers are positive from your first awk.
Try this (and consult the awk man page for the conditional assignments):
I see now what is wrong. It does need to continue as Corona said. I kept on typing and typing not noticing that the ' was what was stopping it from acting as it should and continuing to pick up the rest of the script. This was really helpful. I agree also my code is very messy and therefore everyone knows it is from a beginner; I will look at Rudi's examples to clean it up.
I am trying to look through a directory where the file names are like this: stringnumber_string, and I want to see if I can take the first part of the name and sort it by the number. I tried this:
for i in *_; do
if; then
fileNum=${i%_*};
echo $fileNum
fi
done
but it gives me an error.... (13 Replies)
I am having a problem where the Compute field/column is spilling over to the new line. Here's the piece of code and the o/p:-
Code Sniplet:-
for id in `qstat -u "*" -q "$Queue" -s r |sed -n '3,$ p'|awk -F" " '{print $1}'`
do
NODELIST=`cat /scratch/$id.hostlist.*|awk -F" " '{print $1,$2}'|tr '... (5 Replies)
Hi Experts,
I am trying to get system output to capture inside awk , but not working:
Please advise if this is possible :
I am trying something like this but not working, the output is coming wrong:
echo "" | awk '{d=system ("date") ; print "Current date is:" , d }'
Thanks, (5 Replies)
A have a file
npt02-sr40-syn-dc0p014-32x24drw.log:0. Best Value = 0.00144914
npt02-sr40-syn-dc0p014-32x24drw.log:1. Best Value = 0.00115706
npt02-sr40-syn-dc0p014-32x24drw.log:2. Best Value = 0.00094345
npt02-sr40-syn-dc0p014-32x24drw.log:3. Best Value = 0.000925552... (11 Replies)
hi My requirement is this:
I have a file having around 100000 records pipe delimited. Now I want to compare record 1 with record 2 and similarly record3 with record 4, this goes on.. For this purpose i put a script as follows:
#!bin/ksh
ct_line=1
nxt_line=`expr ${ct_line} + 1`
awk -F "|"... (1 Reply)
I have a script problem that I am not able to solve due my very limited understanding of unix/awk.
This is the contents of test.sh
awk '{print $1}'
From the prompt if I enter:
./test.sh Hello World
I would expect to see "Hello" but all I get is a blank line. Only then if I enter "Hello... (2 Replies)
Actually, I had my first problem before even BEGINNING using my FreeBSD.
The installation guide said I should run the rawrite tool and should do something like
A> rawrite
if i put the the file I want to image-copy and the rawrite.exe in the same directory somewhere. OK done that. Next it asks... (6 Replies)