awk command

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
naren6876
Participant
Posts: 233
Joined: Mon Feb 07, 2005 7:19 pm

awk command

Post by naren6876 »

Hi,
when i use the following command
awk '{ printf }' x > y
data is truncating.

when i use the following command
awk '{ print $0 }' x > y
data is not truncating.

is something related with new line character or anything else?
what could be the reason?.

please shed some light on this.

thanks in advance.
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

$0 returns the whole line. Where I guess, printf receives each word as argument and prints out. So the alignment might vary. But I dont think you get the work truncated.
Btw, where are you using this, and whats your effect of output?
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
naren6876
Participant
Posts: 233
Joined: Mon Feb 07, 2005 7:19 pm

Post by naren6876 »

kumar_s wrote:$0 returns the whole line. Where I guess, printf receives each word as argument and prints out. So the alignment might vary. But I dont think you get the work truncated.
Btw, where are you using this, and whats your effect of output?
I'm using it in a shell script.
My source is a XML file and it has some dummy name and value pairs.
So, by using grep and sed i removed those and finally copying the content to new file with awk '{print f}' x > y.
After copying 1/3rd of the content it gaves the error

Insufficient arguments for awk '{printf}'.

After that i changed it to awk '{print $0}'.
it copies whole content successfully.

But i have been using awk '{print f}' x > y for last 6 months succesfully and suddenly caught up with this error.

any inputs please.
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

It may be restriction of awk input argument that limited to 199.
Since $0 reads as whole line, you might not got it. Anyway whats is the error that you get?
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
naren6876
Participant
Posts: 233
Joined: Mon Feb 07, 2005 7:19 pm

Post by naren6876 »

kumar_s wrote:It may be restriction of awk input argument that limited to 199.
Since $0 reads as whole line, you might not got it. Anyway whats is the error that you get? ...
Insufficient arguments for awk '{printf}'.
lstsaur
Participant
Posts: 1139
Joined: Thu Oct 21, 2004 9:59 pm

Post by lstsaur »

A printf action looks like this:
{ printf format-string, value, value, ... }
The format-string indicates the output format. The given values give the data to be displayed. That's why you got "Insufficient arguments" error for awk '{printf}'.
naren6876
Participant
Posts: 233
Joined: Mon Feb 07, 2005 7:19 pm

Post by naren6876 »

lstsaur wrote:A printf action looks like this:
{ printf format-string, value, value, ... }
The format-string indicates the output format. The given values give the data to be displayed. That's why you got "Insufficient arguments" error for awk '{printf}'.

can't we use awk '{ printf }' without arguments?

Thanks in advance
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

You need at least a format string.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
naren6876
Participant
Posts: 233
Joined: Mon Feb 07, 2005 7:19 pm

Post by naren6876 »

ray.wurlod wrote:You need at least a format string. ...
i have been using

awk '{ printf }' x.xml > y.xml

for the past 6 months without any problem.

i have changed the code to

awk '{ print $0 }' x.xml > y.xml and its working fine now.But, i dont know how to explain it to my boss.

he is asking why it has worked till now?

thanks in advance
narasimha
Charter Member
Charter Member
Posts: 1236
Joined: Fri Oct 22, 2004 8:59 am
Location: Staten Island, NY

Post by narasimha »

I am guessing there could be a newline '\n' in your file which is causing result to be moved to the next line, which might be giving you the impression of it getting truncated.
"print" automatically advances the output to the next line when it prints a line, but "printf" does not.
Narasimha Kade

Finding answers is simple, all you need to do is come up with the correct questions.
lstsaur
Participant
Posts: 1139
Joined: Thu Oct 21, 2004 9:59 pm

Post by lstsaur »

I don't understand why that you didn't get a syntax error when you issued:
awk '{ printf }' x.xml > y.xml

I ran the above statement on the command line; I got the following:
awk: Syntax error Context is:
>>> { printf } <<<

If I put a space between 'print' and 'f', awk '{ print f }' x.xml > y.xml, it ran without error message and created an empty y.xml file.

Are you sure you were not using awk '{ print f }' x > y for the past 6 months.
naren6876
Participant
Posts: 233
Joined: Mon Feb 07, 2005 7:19 pm

Post by naren6876 »

lstsaur wrote:I don't understand why that you didn't get a syntax error when you issued:
awk '{ printf }' x.xml > y.xml

I ran the above statement on the command line; I got the following:
awk: Syntax error Context is:
>>> { printf } <<<

If I put a space between 'print' and 'f', awk '{ print f }' x.xml > y.xml, it ran without error message and created an empty y.xml file.

Are you sure you were not using awk '{ print f }' x > y for the past 6 months.
Yes. i am sure i'm not using awk '{ print f }' x > y.

The exact error message i'm getting is

awk: not enough arguments in printf(Peller/84%, Joseph) or sprintf(Peller/84%, Joseph)
record number 534538

any clues pls
Thanks in advance.
Post Reply