Unable to echo single quotes inside awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unable to echo single quotes inside awk
# 1  
Old 12-10-2012
Unable to echo single quotes inside awk

Code:
[root@gofu ~]# echo 'export HISTFILE=/var/log/history/history_$(uname -n)_$(date +%Y:%b:%d:%H:%M)_$(who am i | awk '{print \$1}')' >> new_file
[root@gofu ~]#
[root@gofu ~]# cat new_file
export HISTFILE=/var/log/history/history_$(uname -n)_$(date +%Y:%b:%d:%H:%M)_$(who am i | awk {print $1})
[root@ofu ~]#

Now how to echo the quotes around the 2nd bracket. in awk. - '{print $1}'

Last edited by Scrutinizer; 12-10-2012 at 04:45 PM.. Reason: code tags
# 2  
Old 12-10-2012
Try this:-
Code:
echo 'export HISTFILE=/var/log/history/history_$(uname -n)_$(date +%Y:%b:%d:%H:%M)_$(who am i | awk '\''{print \$1}'\'')'


Last edited by Yoda; 12-10-2012 at 04:58 PM..
# 3  
Old 12-10-2012
Dont need to escape the "$"

This will do:
Code:
echo 'export HISTFILE=/var/log/history/history_$(uname -n)_$(date +%Y:%b:%d:%H:%M)_$(who am i | awk '\''{print $1}'\'')' >> new_file

Thanks anyway Smilie

Last edited by Scott; 12-10-2012 at 05:45 PM.. Reason: Code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Single quotes insert statement using awk

Hi, Need help, using awk command to insert statement awk -v q="'" '{ print "db2 connect to repolab > /dev/null; " "\n" "db2 -x \" select name from IBMPDQ.PROFILE where managed_database = " q $1"_"$3"__0" q "\"" } ' profile.txt | sh - | awk -v i="'" ' { print "db2 connect to repolab >... (1 Reply)
Discussion started by: Mathew_paul
1 Replies

2. Shell Programming and Scripting

Expansion of variable inside Single Quotes Fails!!

I am unable to expand the value of entry variable inside the nawk command. I tried three different nawk command as below but none of them substitute the value of entry variable. ls *.txt | while IFS='' read -r entry; do #nawk '/<name>/{A=1;++i} A{print >> ("cmd"i"_"$entry)}... (9 Replies)
Discussion started by: mohtashims
9 Replies

3. Shell Programming and Scripting

awk - single quotes as record separator

How do I use single quotes as record separator in awk? I just couldn't figure that out. I know how to use single quotes as field separator, and double quotes as both field and record separator ... (1 Reply)
Discussion started by: locoroco
1 Replies

4. UNIX for Dummies Questions & Answers

awk for inserting a variable containing single and double quotes

Hi i have to insert the below line into a specific line number of another file export MBR_CNT_PRCP_TYPE_CODES_DEL="'01','02','04','05','49','55','UNK'" I have passed the above line to a variable say ins_line. I have used below command to perform the insert awk 'NR==3{print "'"${ins_line}"'"}1'... (1 Reply)
Discussion started by: sathishteradata
1 Replies

5. Shell Programming and Scripting

awk - single quotes as field separator

How can I use single quotes as field separator in awk? (1 Reply)
Discussion started by: locoroco
1 Replies

6. UNIX for Dummies Questions & Answers

Unable to send single and double quotes to command

Hi Unix experts, Believe me, this forum has been really great help and I searched for many things that were already answered before open new post that were just new versions of old one, but with this one, I just can't simply move any forward. This must be quite easy, but I cant find where I... (1 Reply)
Discussion started by: manolain
1 Replies

7. Shell Programming and Scripting

problem with echo inserting single quotes

Consider the following script: #!/bin/bash exclude='Archive PST,SystemState' IFS=$"," rsyncExclusions=$(for exclude in ${exclude}; do echo -n -e --exclude=\"${exclude}\"\ ; done) unset IFS echo rsync $rsyncExclusions test rsync -avh --delete --delete-excluded "$rsyncExclusions"... (7 Replies)
Discussion started by: jelloir
7 Replies

8. Shell Programming and Scripting

single quotes in awk statement

Hi, I have written a code to modify a string say, StringA=abc,def,ghi I need to change it to something like: StringB=This means abc='ABC', This mean def='DEF', This means ghi= 'GHI' StringB=$(echo $StringA | awk -F',' 'BEGIN { OFS="," } { for (i=1; i<=NF;i++) $i="This means... (2 Replies)
Discussion started by: tostay2003
2 Replies

9. UNIX for Dummies Questions & Answers

awk to print ' (single quotes)

I'm building a file with sql delete statements. I need to print the single quotes for the where clause. i.e. delete from Command where CommandName = 'SomeName'; I have the following in my script input=$(pwd)/Cmnd.csv i=0 while read line do if test $i -ge 1; then ... (2 Replies)
Discussion started by: orahi001
2 Replies

10. Shell Programming and Scripting

echo using single quotes

Hi, Please help me to echo the following statement using single quotes Why can't I write 's between single quotes Thanks in advance, Chella (3 Replies)
Discussion started by: chella
3 Replies
Login or Register to Ask a Question