![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to extract first column with a specific character | selamba_warrior | Shell Programming and Scripting | 3 | 05-22-2008 02:14 AM |
| Escaping the * character in ksh. | arvindcgi | Shell Programming and Scripting | 6 | 05-19-2008 06:50 AM |
| [csh] checking for specific character ranges in a variable | userix | Shell Programming and Scripting | 5 | 05-11-2008 04:56 AM |
| How to change a specific character in a file | sdubey | Shell Programming and Scripting | 6 | 02-22-2008 12:30 PM |
| How to add character in specific position of a string? | victorlung | Shell Programming and Scripting | 5 | 09-01-2006 07:33 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hello there,
I have a bit of dirty delimited file, I mentioned dirty because, the delimiter can also appear in wrong positions. However, one uniqueness of this file is whenever the delimiter appear inside the double quote, then do not consider as delimiter, if it appear outside double then consider it as delimiter. contents looks like below abc;def;ghi;"kl;mn;op" ;qrst;uv;w;xyz; AWk inp=$1 nawk -F";" '{ print $1"~"$2"~"$3"~"$4"~"$5"~"$6"~"$7"~"$8; }' $inp >> ${inp}_det.txt gives me ouptut as abc ~def~ghi~"kl~mn~op" ~qrst~uv But expected output is abc ~def~ghi~"kl;mn;op" ~qrst~uv~w~xyz I'm kind of stuck how to escape the double quote . I appreciate any pointers. thanks |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
hmmm
hacky solution is: Code:
tr "\"" "%" <file1 | nawk -F";" '{ print $1"~"$2"~"$3"~"$4"~"$5"~"$6"~"$7"~"$8; }' | tr "%" "\""
EDIT: nope - ignore me - I'm talking rubbish ;-) too early on a monday morning - need more caffeine |
|
#3
|
|||
|
|||
|
Hi,
To be more precise, all the fields are double quoted and delimited by semi colon ; something like: "abc";"def";"ghi";"kl;mn;op" ;"qrst";"uv";"w";"xyz"; I've preprocessed the files by removing all double quote & then noticed, probably that wouldn't work, as I need some sort of marker to tell that any values inside double quote is just value and not delimiter. Somhow struggling to press the right keys |
|
#4
|
||||
|
||||
|
ah, then this should work:
Code:
sed 's/\";"/%/g' file | nawk -F"%" '{ print $1"~"$2"~"$3"~"$4"~"$5"~"$6"~"$7"~"$8; }'
|
|
#5
|
|||
|
|||
|
Thanks Tytalus !!
|
|||
| Google The UNIX and Linux Forums |