LinuxQuestions.org
Visit Jeremy's Blog.
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, 05: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, 07: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, 08:08 AM   #3
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

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

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

Rep: Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 07:42 PM
xargs removes single quotes after awk Poki Linux - Newbie 4 06-26-2009 10:25 AM
Variables within single quotes are not evaluated? Akhran Linux - Newbie 1 03-10-2006 09:32 PM
Using single quotes vs double quotes in PHP strings vharishankar Programming 6 07-11-2005 12:41 PM
replacing single quotes in file names adenardo Linux - General 2 05-27-2005 12:29 PM


All times are GMT -5. The time now is 05:04 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration