How to ignore delimiters inside the quotes?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to ignore delimiters inside the quotes?
# 1  
Old 10-11-2010
How to ignore delimiters inside the quotes?

Hi Experts,
How to ignore any delimiters which is inside the quotes. in awk script.
I am having script which counts number of delimiters from the line now i need count delimiters only separators .

Code:
`grep "14" | cut  -d"="  -f2` -F'~'if (NF-1 != v1)  '

this command counts number of Tilde from line suppose line contains Tilde =14 then correct else error. but
This command finds all the Tilde from line .
I need only column separators to be count.


Thanks & Regards,
Ganesh

Moderator's Comments:
Mod Comment Please use code-tags for code. Thank you.

Last edited by bakunin; 10-11-2010 at 11:10 AM..
# 2  
Old 10-11-2010
I am not sure if i understand you crrectly: you want to process a line with mixed content, some of it inside (double or single) quotes, some of it outside. You want to process only the part outside the quotes.

What you have to do is to cut out everything between (pairs of) quote characters prior to having a look at the line. For example, double quotes:

Code:
print - "abc \"do not process = this\" def=10 \"do not process this = either\"" | sed 's/"[^"]*"//g'

I hope this helps.

bakunin
# 3  
Old 10-11-2010
if you are interested in Perl use the Perl module "Text::ParseWord" :

Example:-

Code:
perl -wle '
use warnings;
use strict;
use Text::ParseWords;
my (@users, @fields);
@users = qq(inforix  x  109  "infomix admin"  "ahmad dibo ya man" ) ; 
@fields = quotewords(" ", 1, @users);
print $_ for(@fields);
'

BR
SmilieSmilieSmilie
# 4  
Old 10-12-2010
Count '~' but not "~" this in awk?

Thanks Bakunin,
But i have an different question Could you pleaase check my once again, Actually in my above question the whole script is in awk script. i want to do this grep command and count for Tilde from line but it should ignore Tilde inbetweet the word,
E.g. ABCD~sdfsd~112~3431~ASD"~"ASDASD
In the above line total Tildes are 5 but i want result as 4 only. That means while counting Tilde it should count only separators not between the double qouts. but above my script gives a result as 5 it is counting "~" this tilde also. Could you please give a solution on that grap command only.

Thanks ,
Ganesh
# 5  
Old 10-12-2010
Something like this,
Code:
echo 'ABCD~sdfsd"~"112~3431~ASD"~"ASDASD' | awk -F'~'  '{for (i=1;i<=NF;i++) {if ($i ~ /\"$/) {++j;}}} END {print NF-j-1}'

# 6  
Old 10-12-2010
Code:
$ echo 'ABCD~sdfsd~112~3431~ASD"x~y"ASDASD' | ruby -e 'a=gets.split("\"");(0..a.size).step(2){|x|p a[x].count("~")}'
4
0

# 7  
Old 10-12-2010
Could you plseae check for this script!

Hi Pravin,
Thanks for reply,you solution is working fine but could you give me some modification on my scritp. just have a look on that Actually i am not be able to modify my script. i am using nawk insidr grep to count Tilde but according to your script o have to give that line here i am referang constant from another file my script is as below.
Code:
{
nawk -v v1=`grep "INT_CNT"  $propfile | cut -d"=" -f2` -F'~' '{if (NF-1 != v1)
{print "Error in " $0 " at line number "NR " tilde count= " NF-1 }}' $data2
}

In the above file i need to add command like just ignore Tilde fro double qoutes. this script is working fine please give some solution on this script only. i need one more if condion so that i can check if Tilde comes in only double qouts then ignore and count remaining Tilde. like that,

Thanks & Regards,
Ganesh.

Last edited by Scott; 10-12-2010 at 07:09 AM.. Reason: Use code tags, please.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Expansion of variable inside Single Quotes Fails!!

I am unable to expand the value of entry variable inside the nawk command. I tried three different nawk command as below but none of them substitute the value of entry variable. ls *.txt | while IFS='' read -r entry; do #nawk '/<name>/{A=1;++i} A{print >> ("cmd"i"_"$entry)}... (9 Replies)
Discussion started by: mohtashims
9 Replies

2. Shell Programming and Scripting

Skip the delimiter with in double quotes and count the number of delimiters during data extract

Hi All, I'm stuck-up in finding a way to skip the delimiter which come within double quotes using awk or any other better option. can someone please help me out. Below are the details: Delimited: | Sample data: 742433154|"SYN|THESIS MED CHEM PTY.... (2 Replies)
Discussion started by: BrahmaNaiduA
2 Replies

3. Shell Programming and Scripting

TCL - quotes inside a string assigned to a var

I know that set line "This is a line." puts whats between " inside the var line. But How do I do the same for set line "This is a line "with quotations" inside the string." (2 Replies)
Discussion started by: popeye
2 Replies

4. Shell Programming and Scripting

awk print - fields separated with comma's need to ignore inbetween double quotes

I am trying to re-format a .csv file using awk. I have 6 fields in the .csv file. Some of the fields are enclosed in double quotes and contain comma's inside the quotes. awk is breaking this into multiple fields. Sample lines from the .csv file: Device Name,Personnel,Date,Solution... (1 Reply)
Discussion started by: jxrst
1 Replies

5. Shell Programming and Scripting

Preserve commas inside double quotes (perl)

Hi, I have an input file like this $ cat infile hi,i,"am , sam", y hello ,good, morning abcd, " ef, gh " ,ij no, "good,morning", yes, "good , afternoon" from this file I have to split the fields on basis of comma"," however, I the data present inside double qoutes should be treated as... (3 Replies)
Discussion started by: sam05121988
3 Replies

6. Shell Programming and Scripting

Unable to echo single quotes inside awk

# echo 'export HISTFILE=/var/log/history/history_$(uname -n)_$(date +%Y:%b:%d:%H:%M)_$(who am i | awk '{print \$1}')' >> new_file # # cat new_file export HISTFILE=/var/log/history/history_$(uname -n)_$(date +%Y:%b:%d:%H:%M)_$(who am i | awk {print $1}) # Now how to echo the quotes around the... (2 Replies)
Discussion started by: proactiveaditya
2 Replies

7. UNIX for Dummies Questions & Answers

Remove two delimiters, space and double quotes

I would like to know how to replace a space delimiter with a ^_ (\037) delimiter and a double quote delimiter while maintaining the spaces inside the double quotes. The double quote delimiter is only used on text fields. I'd prefer a one-liner, but could handle a function or script that accepts... (4 Replies)
Discussion started by: SteveDWin
4 Replies

8. Shell Programming and Scripting

How to ignore delimiter between the quotes?

Hi Guys, I have following script which counts number of tilde in file but i want to count tilde which are field saparator.but my script count tilde between word also what i need is if line is like abcd~das~1212~fsddf~ so tilde count is = 4 if line like abcd~das~1212~fsd"~"df~ so tilda count... (4 Replies)
Discussion started by: Ganesh Khandare
4 Replies

9. Shell Programming and Scripting

sed removing comma inside double quotes

I have a csv file with lines like the followings 123456,"ABC CO., LTD","XXX" 789012,"DEF LIMITED", "XXX" before I bcp this file to database, the comma in "CO.," need to be removed first. My script is cat <filename> | sed 's/"CO.,"/"CO."/g' but it doesn't work. Can anyone here able to... (2 Replies)
Discussion started by: joanneho
2 Replies

10. Shell Programming and Scripting

escaping double-quotes inside the script?

I'm having a strange problem with escaping double-quotes. I have a script that looks like this: #!/bin/bash for HOST in `cat $INFILE | grep -v ^#` do for VFILER in `some_command` do echo " " echo -e '\E The problem with ssh command... (3 Replies)
Discussion started by: GKnight
3 Replies
Login or Register to Ask a Question