- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Awk functionality
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2001 07:20 AM
05-28-2001 07:20 AM
I am trying to build a line from a file using awk and I am having a problem with inserting ' into the line as the ' charatcter is used to delimit the awk function. For example
cat file|awk '{print "hi dave \'" $1}'
su: Syntax error: `"' is not matched.
my output should be
hi dave ' walley
Can anybody tell me how to include the single quote in the output.
Thanking you
Dave
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2001 07:48 AM
05-28-2001 07:48 AM
Re: Awk functionality
Your problem is not the single quote in awk but rather the single in the surrounding shell quote. On easy way around this is to build an awk script 'on the fly' using the 'here doc' convention. This also allows you to build up more than simple one-liners.
The script build your awk file and writes it to a temp file, executes awk, and then removes the temp file. Being an old C programmer i also swapped your print to a printf - it's more powerful.
Something like this:
#!/usr/bin/sh
TDIR=${TMPDIR:-/var/tmp}
PID=${$}
A1=${TDIR}/X${PID}_1.awk
cat << !EOF! > $A1
{
printf("Hi Dave ' %s\n",\$1)
}
!EOF!
cat myfile | awk -f ${A1}
STAT=$?
rm -f $A1
exit $STAT
If my typing is correct, that should do it. Note that within the 'here docs' section the '$' has to be escaped with '\'.
Regards, Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2001 08:09 AM
05-28-2001 08:09 AM
Re: Awk functionality
I have tried your suggestion and received absolutely nothing.
By running the myfile line I get
syntax error The source line is 5.
The error context is
!EOF! >>>
<<<
dave
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2001 08:13 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2001 08:33 AM
05-28-2001 08:33 AM
Re: Awk functionality
My typing was ok but apparently the browser doesn't do a perfect job of copy/paste. When I copied in my own example, it didn't work. The problem was extra whitespace after !EOF! at the end of the here docs section. Remove the extra spaces at the end of the line and all should be well. And again, I deliberately made this more complex than a one-liner in case your script gets more complicated.
Regards, Clay