awk command
Moderators: chulett, rschirm, roy
awk command
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.
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.
$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?
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'
I'm using it in a shell script.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?
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.
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
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
i have been usingray.wurlod wrote:You need at least a format string. ...
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
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.
"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.
Finding answers is simple, all you need to do is come up with the correct questions.
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.
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.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.
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.