|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||
|
||||
|
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.txtBut the ouput is coming without double quotes: "1-23-test_test1-test2"|#GT_properties_xyz Please help in fixing this issue!!
Last edited by vbe; 02-27-2012 at 01:36 PM.. |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
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 | ||
|
![]() |
| Thread Tools | Search this Thread |
| 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 |
|
|