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

printf problem with % character in a string

Status
Not open for further replies.

inma

Technical User
Apr 5, 2001
49
ES
Hi All,
I have several lines in a text flie like this:

#line 1 aaa aaaaaa # AAAA
#line 2 6% BBB # AAAA
line 3 bbbbbbbbbbb bbbb
#line 4 cccc CCCCC
line 5 bbbbbbb bbbb

The aout file wil be:
#line 1 aaa aaaaaa # AAAA
#line 2 6% BBB # AAAA line 3 bbbbbbbbbbb bbbb
#line 4 cccc CCCCC line 5 bbbbbbb bbbb

I am using this awk for joining lines if first character is not a #:

awk '
NR==1 {printf $0;next}
/^#/{printf "\n"$0;next}{printf " "$0}' in>out

This command stops at line 2 because of %, and this message appears:
awk: There is not enough arguments in printf( BBB # AAAA
register number 2.
Any help offered is truly appreciated.
thanks

 
Try this:
Code:
awk '
NR==1 {printf "%s",$0;next}
/^#/{printf "%s\n",$0;next}{printf " %s",$0}' in>out


Hope This Help
PH.
 
Thanks PH, it works perfectly
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top