Add double quotation to Output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Add double quotation to Output
# 1  
Old 02-05-2016
Add double quotation to Output

Code:
tail -n +7 1.txt |head -n -2|awk '{print "sql", $1,"-c groom table " $5 ,"versions"}'

Code:
sql DB1 -c groom table T1 versions
sql DB2 -c groom table T2 versions
sql DB3 -c groom table T3 versions

but i want out should be

Code:
sql DB1 -c "groom table T1 versions"
sql DB2 -c "groom table T2 versions"
sql DB3 -c "groom table T3 versions"


when i try this

Code:
tail -n +7 1.txt |head -n -2|awk '{print "sql", $1,""""-c groom table " $5 ,"versions"}'
awk: {print "sql", $1,""""-c groom table " $5 ,"versions"}
awk:                                                      ^ unterminated string

Can some one suggest how can i do achieve this ?
# 2  
Old 02-05-2016
Try:
Code:
awk '{print "sql " $1 " \"-c groom table " $5 " versions\""}'

# 3  
Old 02-05-2016
Hello rocking77,

Could you please try this and let me know if this helps, this solution considers like you have data in sample Input_file shown format only.
Code:
awk -vs1="\"" -F"-c " '{A=$1 FS;for(i=2;i<=NF;i++){A=A?A s1 $i s1:s1 $i s1};print A;A=""}'  Input_file

Output will be as follows.
Code:
sql DB1 -c "groom table T1 versions"
sql DB2 -c "groom table T2 versions"
sql DB3 -c "groom table T3 versions"

EDIT: Or let's try to solve the command shown by you in post, not tested though.
Code:
tail -n +7 1.txt | head -n -2| awk -vs1="\"" '{print "sql " $1 " -c " s1 "groom table " $5 " versions" s1}'

Thanks,
R. Singh

Last edited by RavinderSingh13; 02-05-2016 at 04:48 AM.. Reason: Added a solution where user was getting problem
# 4  
Old 02-05-2016
Variation with printf:
Code:
awk '{printf "sql %s -c \"groom table %s versions\"\n", $1, $5}'

Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Question regarding quotation syntax

Hey guys, my first post on UNIX Forums(much overdue IMO)! I've got this bit of code that doesn't seem to be working correctly for an Android app I'm working on: "screen -S gmod1 -p 0 -X stuff " & "" & command.text & "`echo -ne '\015'`""" Basically it types command.text(variable determined... (4 Replies)
Discussion started by: stingwraith
4 Replies

2. Shell Programming and Scripting

Why double quotation marks doesn't work in ksh function parameters passing?

I'm working on AIX 6, ksh shell. The parameters are some strings quotated by double quotation marks which from a file. They are quotated because there may be spaces in them. Example: "015607" "10" " " "A"I want to pass these parameters to a shell function by writing the following command: ... (4 Replies)
Discussion started by: Shimmey
4 Replies

3. Shell Programming and Scripting

Shell Script help for Quotation Delimited File

I need help extracting a column in a file separated by quotations. I would like to extract the first column of data and write it to a flat text file. EXAMPLE of data: "c6e181396a1100ba19c53a6757a845c4","2012-05-18","email" "70879000563753bb9051b4ab8df43ac4","2012-05-18","email"... (5 Replies)
Discussion started by: nickytcom
5 Replies

4. UNIX for Dummies Questions & Answers

PHP parsing quotation

Delete the post. (0 Replies)
Discussion started by: yifangt
0 Replies

5. Shell Programming and Scripting

Count number of character occurence but not from quotation marks

I have the following string: 31-01-2012, 09:42:37;OK;94727132638;"Mozilla/5.0 (Linux; U; Android 2.2.1)";3G;WAP;I need a script which is counting the occurrence of semicolons ( ; ) but exclude the ones from the quotation marks. In the string given as example there are 8 semicolons but the script... (3 Replies)
Discussion started by: calinlicj
3 Replies

6. UNIX for Advanced & Expert Users

quotation mark use

Hi colleagues, I am development a script. this flat file pp.txt contain this tree lines. prueba prueba1 prueba2 cat pp.txt |awk '{print a}' |while read a do var=`db2 select count(*) from $a`" echo $var done executing var show me error. I need var contain: db2... (1 Reply)
Discussion started by: systemoper
1 Replies

7. UNIX for Dummies Questions & Answers

Tricky Quotation Question

Hi, I am at a point in my script where I defined the number of the command line parameter I would like to set a variable equal to: parameter_number=14 I would then like to set a variable equal to the correct parameter: variable=$parameter_number The issue here is that {} is required... (2 Replies)
Discussion started by: msb65
2 Replies

8. Shell Programming and Scripting

enclose a line with quotation marks

i have a file like this aaaa bbbb cccc aaa aaaa aa cccccccccccccccc aaaaaaa aaaa aaaa i want to enclose this lines with double quotation: "aaaa bbbb cccc" "aaa aaaa" "aa cccccccccccccccc" "aaaaaaa aaaa aaaa" any idea? (preferably without using sed) thanks in advance... (3 Replies)
Discussion started by: gfhgfnhhn
3 Replies
Login or Register to Ask a Question