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!

How to PRINTF special characters?

Status
Not open for further replies.

whatisthis987

IS-IT--Management
Apr 24, 2007
34
US
Hi,
== Beginning of name_list.file ===
ALAN*
ALEX?
BEN
== end of name_list.file ==

== Beginninf of Shell script ==
set name_list = name_list.file
foreach mm (`cat ${name_list}`)
printf \" >> output_file
printf $mm >> output_file
printf \" >> output_file
printf " " >> output_file
end
== end of Shell script ==

I'm getting error messages "printf: No match.". I tried adding a backslash before the asterisk and question mark but that didn't help.

Could you please help?
 
I hate csh-like shells ;-)
You may try this:
Code:
sed 's!^!"!;s!$!"!' name_list.file | tr '\n' ' ' > output_file

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks, PH. It returns the following error:
sed: -e expression #1, char 10: Unknown option to 's'
 
What is YOUR actual code ?
Have you tried mine in a ksh-like shell ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Try using quotes around the $mm variable:

== Beginning of Shell script ==
set name_list = name_list.file
foreach mm (`cat ${name_list}`)
printf \" >> output_file
printf [red]"[/red]$mm[red]"[/red] >> output_file
printf \" >> output_file
printf " " >> output_file
end
== end of Shell script ==


HTH,

p5wizard
 
Hi p5wizard,
That works! I didn't know it could be that simple. I tried adding %s in front of the $mm to define it as string but that didn't help.

Guys, thank you so much for contributing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top