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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"unexpected newline or end of string" in XP script

Status
Not open for further replies.

jjohnn

Technical User
Feb 11, 2003
43
US
dir | gawk "{sub(/n, ,$0}"

on Win XP gives the error above.

dir | gawk "{print $5}" lists the files, one to a line. I want to remove the newlines.

Any suggestions?
 
Hi

Try to set the [tt]RS[/tt] ( record separator ) and/or [tt]ORS[/tt] ( output record separator ) internal variables. They are by default [tt]\n[/tt], while DOS/Windows uses [tt]\r\n[/tt] as end of line mark.

Feherke.
 
dir | gawk "{printf \"%s \",$5}"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
That does not seem to work for me:

Q:\scripts\scrap>type dir2.bat
dir | gawk "{printf \"%s \",$5}"

Q:\scripts\scrap>dir2.bat

Q:\scripts\scrap>dir | gawk "{printf \"s \",$5}"
s s s s s s s s s s s
Q:\scripts\scrap>

Removing the format specifier does work in this case:
Q:\scripts\scrap>type dir1.bat
dir | gawk "{printf( $4\" \" )}"

Q:\scripts\scrap>dir1

Q:\scripts\scrap>dir | gawk "{printf( $4\" \" )}"
Q is . .. dir1.bat dir2.bat bytes bytes
Q:\scripts\scrap>

IS ther a book on making windows scripts using installed utilities, simlar to the plethora of books on making unix shell scripts?

 
dir /b | gawk "{printf $0\" \"}"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top