single quotes in awk statement


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting single quotes in awk statement
# 1  
Old 01-02-2009
single quotes in awk statement

Hi,

I have written a code to modify a string say,

Code:
StringA=abc,def,ghi

I need to change it to something like:

Code:
StringB=This means abc='ABC', This mean def='DEF', This means ghi= 'GHI'

Code:
StringB=$(echo $StringA | awk -F',' 'BEGIN { OFS="," } { for (i=1; i<=NF;i++) $i="This means "$i"='ABC'")) THEN '' ELSE " $1 ; print $0 }')

I am not able to print the single quotes to the output or rather assign to String B
# 2  
Old 01-02-2009
If I understand you correctly, you just need to escape the single quotes that you are wanting to print.

echo 'This is a \'test\''
# 3  
Old 01-02-2009
Sorry i forgot to put that in my earlier example. I did use the \ to escape the single quotes, but it doesn't work
Code:
StringB=$(echo $StringA | awk -F',' 'BEGIN { OFS="," } { for (i=1; i<=NF;i++) $i="This means "$i"=\'ABC\'")) THEN '' ELSE " $1 ; print $0 }')

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

Issue with Single Quotes and Double Quotes for prompt PS1

Hi, Trying to change the prompt. I have the following code. export PS1=' <${USER}@`hostname -s`>$ ' The hostname is not displayed <abc@`hostname -s`>$ uname -a AIX xyz 1 6 00F736154C00 <adcwl4h@`hostname -s`>$ If I use double quotes, then the hostname is printed properly but... (3 Replies)
Discussion started by: bobbygsk
3 Replies

3. Shell Programming and Scripting

Unable to echo single quotes inside awk

# echo 'export HISTFILE=/var/log/history/history_$(uname -n)_$(date +%Y:%b:%d:%H:%M)_$(who am i | awk '{print \$1}')' >> new_file # # cat new_file export HISTFILE=/var/log/history/history_$(uname -n)_$(date +%Y:%b:%d:%H:%M)_$(who am i | awk {print $1}) # Now how to echo the quotes around the... (2 Replies)
Discussion started by: proactiveaditya
2 Replies

4. 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

5. 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

6. 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

7. Shell Programming and Scripting

Having a terrible problem with quotes/single quotes!

Hello. I'm trying to write a bash script that uses GNU screen and have hit a brick wall that has cost me many hours... (I'm sure it has something to do with quoting/globbing, which is why I post it here) I can make a script that does the following just fine: test.sh: #!/bin/bash # make... (2 Replies)
Discussion started by: jondecker76
2 Replies

8. Shell Programming and Scripting

How to alias an awk command with single and double quotes?

Hi, I am trying to write the following command as an alias in my .bashrc file. bjobs -u all | awk '{if (NR > 1) {username++;}}END{{print"\nJOBS BY USER:\n"} for (i in username) {print username,i;}{print"\n Total Jobs=",NR-1,"\n" }}' The command simply puts how many jobs each user is... (2 Replies)
Discussion started by: jacekmaciek
2 Replies

9. Shell Programming and Scripting

Double quotes or single quotes when using ssh?

I'm not very familiar with the ssh command. When I tried to set a variable and then echo its value on a remote machine via ssh, I found a problem. For example, $ ITSME=itsme $ ssh xxx.xxxx.xxx.xxx "ITSME=itsyou; echo $ITSME" itsme $ ssh xxx.xxxx.xxx.xxx 'ITSME=itsyou; echo $ITSME' itsyou $... (3 Replies)
Discussion started by: password636
3 Replies

10. 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
Login or Register to Ask a Question