|
|
lf/cr affecting awk script?
dear all,
i have come across a strange/unexpected behaviour of my awk script and i
was hoping maybe someone could shed a bit of light on this issue.
i have a large number of files from which i extract data using the
following script:
(FNR==1) {found=0}
($1=="Hold") {output=$3}
($1 ~ /\*/ && found==0) {print output; found=1}
this works well and produces 1 line of output for every file. now i'd
like to have the filename in addition to the $3 (number). so i changed
the last line to
($1 ~ /\*/ && found==0) {print output FILENAME; found=1}
which again seems to work nicely. for the first half of the files it
produces nicely the expected output. however, suddenly it stops printing
$3 and each time i only get the the filename printed. i checked by hand
and it should work on all files (=should print $3 for all files).
to verify this i changed the last line, this time to
($1 ~ /\*/ && found==0) {print output; print FILENAME; found=1}
and then i get the result for all files, but now on two lines.
the only difference i was able to find between the input files is that
some seem to have cr/lf (or any combination thereof) at the end of the
lines. as this is the only difference i could find i assume this to be
the cause for this.
could anybody explain why the cr/lf so strongly affects the behaviour of
the script?
thanks for any help,
tom
|
|
0
|
|
|
|
Reply
|
Thomas
|
6/23/2005 6:53:33 AM |
|
ok, i've found the problem.
awk was actually doing everything fine, just as it should.
the problem was that my editor interpreted the cr/lf in the middle of
the line as beginning of the line, not showing the $3 value printed
before it.
....and awk still stands strong...
cheers,
tom
Thomas Toth wrote:
> dear all,
>
> i have come across a strange/unexpected behaviour of my awk script and i
> was hoping maybe someone could shed a bit of light on this issue.
>
> i have a large number of files from which i extract data using the
> following script:
>
> (FNR==1) {found=0}
> ($1=="Hold") {output=$3}
> ($1 ~ /\*/ && found==0) {print output; found=1}
>
> this works well and produces 1 line of output for every file. now i'd
> like to have the filename in addition to the $3 (number). so i changed
> the last line to
>
> ($1 ~ /\*/ && found==0) {print output FILENAME; found=1}
>
> which again seems to work nicely. for the first half of the files it
> produces nicely the expected output. however, suddenly it stops printing
> $3 and each time i only get the the filename printed. i checked by hand
> and it should work on all files (=should print $3 for all files).
>
> to verify this i changed the last line, this time to
>
> ($1 ~ /\*/ && found==0) {print output; print FILENAME; found=1}
>
> and then i get the result for all files, but now on two lines.
>
> the only difference i was able to find between the input files is that
> some seem to have cr/lf (or any combination thereof) at the end of the
> lines. as this is the only difference i could find i assume this to be
> the cause for this.
>
> could anybody explain why the cr/lf so strongly affects the behaviour of
> the script?
>
> thanks for any help,
>
> tom
>
>
>
|
|
0
|
|
|
|
Reply
|
Thomas
|
6/23/2005 8:01:59 AM
|
|
|
1 Replies
167 Views
(page loaded in 0.037 seconds)
Similiar Articles: gnuplot data.txt file with CR+LF - comp.graphics.apps.gnuplot ...... CR+LF carriage returns? If there is not, does anyone have a windows script that can remove the CR? ... carriage return, newline, and combinations - comp.lang.awk ... gnuplot data.txt file with CR+LF ... replace hex sequence - comp.lang.awkawk script to convert dec to hex - comp.lang.awk replace hex sequence - comp ... LF with CR + LF - comp.lang.xharbour replace hex sequence - comp.lang.awk Replace LF with CR ... efficiency in awk - comp.lang.awkAwk scripts are written for purposes of ease, portability, prototype and experiment ... other awk interpreters, and the problems that make me avoid it won't affect most awk ... carriage return, newline, and combinations - comp.lang.awk ...... is no text/numbers. i'd like to use awk but i am aware of tr, sed options. AFAIK, \r is carriage return ... with octal escape sequences: \015 for CR and \012 for line feed ... Pulling out fields in a CSV file - comp.lang.awkI figure this would be easier to accomplish with Awk. ... One of these days I'll write a nice script for this task ... if a field has embedded commas, doublequotes, CR, or LF ... find/replace line of code (with carriage return) - comp.soft-sys ...Replace LF with CR + LF - comp.lang.xharbour Excel - Find/replace Carriage Return & Line Feed ... Capture windows command return code to variable in awk script ..... I have ... Insert a string into the text of textarea. Caret? IE question ...... in my TEXTAREA box - 01234567890 I want - using script ... TextArea with \n - comp.lang.java.gui Replace LF with CR + LF ... AWK question - split string into variables - comp ... conversion tables on FTP - comp.sys.ibm.as400.miscFTP LF/CR Problem - comp.sys.unisys conversion tables on ... application", which then calls a script, which ftp's ... conversion to scientific notation - comp.lang.awk ... n ... Converting Btrieve DTA file to csv or txt - comp.databases.btrieve ...I am looking for a command line ... I want to create a script-file which contains to data and ... ... if needed.) /F1 Change CR/LF to space ... ... in a CSV file - comp.lang.awk ... Writing non ASCII text files - comp.lang.tclI have written a tcl script that aims to write text ... are used in files, whereas carriage-return ... Temp/ utf8Test.txt wb): (-translation lf ... Harald Kierer - awk CR/LF issue - Cygwinawk CR/LF issue. From: Harald Kierer <Harald dot Kierer at astrum dot ... print \"456\" >> v_Out; }" > x.awk [create simple awk script that outputs some lines] [/t] $ awk ... AWK ProgrammingThis doesn't affect the execution of the awk program but it does make ... endings (LF) to standard DOS line endings (CR,LF). awk programs are often called "scripts ... 7/30/2012 10:15:53 AM
|
|
|
|
|
|
|
|
|