Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-27-2012
Registered User
 
Join Date: Feb 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Help populating double quotes using awk

Want to populate double quotes for each filed using awk:

Input: cat file.txt => "1-23-test_test1-test2"

Required output :

"1-23-test_test1-test2"|"#GT_properties_xyz"

Was trying the below command on solaris 9 machine :

Code:
awk -F"|" '{print $1"|""#GT_properties_xyz"}' file.txt

But the ouput is coming without double quotes:

"1-23-test_test1-test2"|#GT_properties_xyz

Please help in fixing this issue!!

Moderator's Comments:
Please use next time
code tags for your code and data

Last edited by vbe; 02-27-2012 at 01:36 PM..
Sponsored Links
    #2  
Old 02-27-2012
Mead Rotor
 
Join Date: Aug 2005
Location: Saskatchewan
Posts: 16,381
Thanks: 491
Thanked 2,535 Times in 2,418 Posts
If you want literal quotes in there, put literal quotes in there, escaped with \ so awk won't take them to be the start/end of its own strings.


Code:
awk -v OFS='|' '{ $2="\"#GT_properties_xyz\"" } 1' file.txt

Sponsored Links
    #3  
Old 02-27-2012
Registered User
 
Join Date: Feb 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks, but if one is dealing with 5 or 6 data inputs/field seperators. ex: if the below is the required output :


"1-23-test_test1-test2"|"#GT_properties_xyz"|"test1"|"1000"|"LAST"

---------- Post updated at 12:19 AM ---------- Previous update was at 12:11 AM ----------

Thanks, but if one is dealing with 5 or 6 data inputs/field seperators. ex: if the below is the required output :


"1-23-test_test1-test2"|"#GT_properties_xyz"|"test1"|"1000"|"LAST"
    #4  
Old 02-27-2012
Mead Rotor
 
Join Date: Aug 2005
Location: Saskatchewan
Posts: 16,381
Thanks: 491
Thanked 2,535 Times in 2,418 Posts
Don't bump posts.

If that's the output you want, what's the input you had?


Code:
awk -F'|' -v OFS='|' '{ $(NF+1)="\"#GT_properties_xyz\"" } 1' file.txt

Sponsored Links
    #5  
Old 02-27-2012
Registered User
 
Join Date: Feb 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Input: cat file.txt => "1-23-test_test1-test2"

Required output :

"1-23-test_test1-test2"|"#GT_properties_xyz"|"test1"|"1000"|"LAST"
Sponsored Links
    #6  
Old 02-27-2012
Mead Rotor
 
Join Date: Aug 2005
Location: Saskatchewan
Posts: 16,381
Thanks: 491
Thanked 2,535 Times in 2,418 Posts
Okay. awk will let you cheat and put two columns in one column, so:


Code:
awk -F'|' -v OFS="|" '{ $1=$1 FS "\"#GT_properties_xyz\"|\"test\"|\"1000\"|\"LAST\"" } 1' filename

Sponsored Links
    #7  
Old 02-27-2012
Registered User
 
Join Date: Feb 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Seems some problem with the syntax, command not working:

Code:

bash-2.05$ awk -F'|' -v OFS="|" '{ $1=$1 FS "\"#GT_properties_xyz\"|\"test\"|\"1000\"|\"LAST\"" } 1' file.txt
awk: syntax error near line 1
awk: bailing out near line 1
bash-2.05$
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Replace double double quotes using AWK/SED Bhuvaneswari Shell Programming and Scripting 2 08-17-2011 07:04 AM
Using double quotes in awk dips_ag Shell Programming and Scripting 9 04-01-2011 02:30 AM
grep single quotes or double quotes george_vandelet UNIX for Dummies Questions & Answers 2 10-27-2010 11:23 AM
Single quotes and double quotes sol_nov Shell Programming and Scripting 5 09-16-2009 09:44 PM
Double quotes or single quotes when using ssh? password636 Shell Programming and Scripting 3 05-29-2008 08:52 PM



All times are GMT -4. The time now is 02:48 PM.