LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-27-2011, 04:27 AM   #1
caspernoome
LQ Newbie
 
Registered: Jul 2011
Posts: 2

Rep: Reputation: Disabled
Printing single quotes with awk


Hi,

I have the following command, which works fine:

ll /backup/PROD |grep PROD_ |awk -F" " '{print "catalog backuppiece /backup/PROD/"$9";"}'

The output is:

catalog backuppiece /backup/PROD/PROD_29mi42vn_1_1;

BUT... I want single quotes in the result. One before /back.. and one before the ;
Like this:

catalog backuppiece '/backup/PROD/PROD_29mi42vn_1_1';

How do I do that? I tried using \' but it does not work.
The following command works, but I get an error message, which prevents me from using the command in a bash file:

ll /backup/PROD |grep PROD_ |awk -F" " '{print "catalog backuppiece \'\''/backup/PROD/"$9"\'\'';"}'
awk: warning: escape sequence `\'' treated as plain `''

Regards,

Casper
 
Old 07-27-2011, 06:12 AM   #2
caspernoome
LQ Newbie
 
Registered: Jul 2011
Posts: 2

Original Poster
Rep: Reputation: Disabled
Hi,

I found a solution to this question - No need for any replies then.

I used awk -v

ls -l /backup/PROD |grep PROD_ |awk -F" " -v xx="'" '{print "catalog backuppiece " xx "/backup/PROD/"$9 xx";"}'

Output is:

catalog backuppiece '/backup/PROD/PROD_29mi42vn_1_1';


Regards,

Casper
 
Old 07-27-2011, 07:08 AM   #3
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
There is a much better way:

Code:
awk 'BEGIN { print "This is a single qoute: '\'' And this is, too: '"'"'" }'
 
Old 07-27-2011, 10:30 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Or an even better idea:
Code:
awk '{print "catalog backuppiece \047"FILENAME"\047;";nextfile}' /backup/PROD/*PROD_*
The usual story here would also be not to parse ls as on my machine I only have 8 fields total so your $9 would fail for me.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Python - string to omit the single quotes (') linuxuser111 Programming 1 03-18-2011 06:42 PM
xargs removes single quotes after awk Poki Linux - Newbie 4 06-26-2009 09:25 AM
Variables within single quotes are not evaluated? Akhran Linux - Newbie 1 03-10-2006 08:32 PM
Using single quotes vs double quotes in PHP strings vharishankar Programming 6 07-11-2005 11:41 AM
replacing single quotes in file names adenardo Linux - General 2 05-27-2005 11:29 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration