The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
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 06:14 AM
Escaping the * character in ksh. arvindcgi Shell Programming and Scripting 6 05-19-2008 10:50 AM
[csh] checking for specific character ranges in a variable userix Shell Programming and Scripting 5 05-11-2008 08:56 AM
How to change a specific character in a file sdubey Shell Programming and Scripting 6 02-22-2008 03:30 PM
How to add character in specific position of a string? victorlung Shell Programming and Scripting 5 09-01-2006 11:33 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-28-2008
brainyoung brainyoung is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 13
Exclamation Escaping specific character in awk

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
  #2 (permalink)  
Old 01-28-2008
Tytalus's Avatar
Tytalus Tytalus is offline Forum Advisor  
echo {1..9}^2\;|bc
  
 

Join Date: Jun 2003
Location: Scotland
Posts: 431
hmmm

hacky solution is:


Code:
tr "\"" "%" <file1 | nawk -F";" '{ print $1"~"$2"~"$3"~"$4"~"$5"~"$6"~"$7"~"$8; }' | tr "%" "\""

i.e. convert the "'s to %'s then map them back later....


EDIT: nope - ignore me - I'm talking rubbish ;-) too early on a monday morning - need more caffeine
  #3 (permalink)  
Old 01-28-2008
brainyoung brainyoung is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 13
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 (permalink)  
Old 01-28-2008
Tytalus's Avatar
Tytalus Tytalus is offline Forum Advisor  
echo {1..9}^2\;|bc
  
 

Join Date: Jun 2003
Location: Scotland
Posts: 431
ah, then this should work:


Code:
sed 's/\";"/%/g' file | nawk -F"%" '{ print $1"~"$2"~"$3"~"$4"~"$5"~"$6"~"$7"~"$8; }'

same sort of trick - replace ";" with %, and use that % as delimeter,
  #5 (permalink)  
Old 01-28-2008
brainyoung brainyoung is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 13
Thanks Tytalus !!
  #6 (permalink)  
Old 12-12-2008
tosattam tosattam is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 13
Hi

I have a \ (backslash) as delimiter and i want a specific column from that. I have been unable to do that using either awk or sed

Input
tosattam123\mattasewq213

i want the Output
mattasewq213

I have tried to escape the \ with / " ' and many other as well but to no avail

can anybody help
  #7 (permalink)  
Old 12-12-2008
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131

Code:
echo 'tosattam123\mattasewq213' | awk -F'\\' '{print $2}'

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:30 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0