How to ignore delimiter between the quotes?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to ignore delimiter between the quotes?
# 1  
Old 10-08-2010
Error 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
Code:
abcd~das~1212~fsddf~

so tilde count is = 4
if line like
Code:
abcd~das~1212~fsd"~"df~

so tilda count is =4 onlly it should not give count as 5 that means it should ignor ~ between "~" if it comes in between the any word. Please give me solution in my script only.
Code:
#!/bin/bash
WORK_DIR=/export/opt/rtrupld/autosys/scripts_old
DATA_DIR=/cdirect/rtrupld/incoming/intellect
DATA_DIR1=/cdirect/rtrupld/incoming/opics
data1=$DATA_DIR/INTELLECT_TOK_MMRTRCASHFLOW*.txt

if [ $var1 = "INTELLECT"  ] &&  [ $var2  = "TOK"  ]
then
  echo"-------------------------------ERROR IN CASHFLOW HANDOFF-------------------------------------------------"
{
nawk -v v1=`grep "INTELLECT_TOK_CASHFLOW_FLD_COUNT"  $propfile | cut -d"=" -f2` -F'~' '{if (NF-1 != v1)
{print "Error in " $0 " at line number "NR " tilde count= " NF-1 }}' $data1
}

Here path just ignore it properties file value of INTELLECT_TOK_CASHFLOW_FLD_COUNT" is take count of tilde

Thanks & Regards,
Ganesh.

Last edited by Franklin52; 10-08-2010 at 07:23 AM.. Reason: Please use code tags!
# 2  
Old 10-08-2010
Try:
Code:
echo 'abcd~das~1212~fsd"~"df~' |perl -pe '$_=()=/\w~/g;'

This User Gave Thanks to Klashxx For This Post:
# 3  
Old 10-08-2010
MySQL

Code:
# echo 'abcd~das~1212~fsd"~"df~' |sed 's/[^\"~\"]//g;s/\"~\"//g;s/.$//'|wc -c
4

# 4  
Old 10-08-2010
Can even be done within a shell
Code:
bash$ IN='abcd~das~1212~fsd"~"df~'
bash$ A=${IN//\"~\"/}; arr=( ${A//\~/ } ); echo ${#arr}
4
bash$

# 5  
Old 10-08-2010
But what if the text inside the double quotes contains other characters than tilde. Then you would need something like this:
Code:
$ echo 'abcd~das~1212~fsd"yyr~yyr"df~' | awk '{gsub(/"[^"]*"/,x);print gsub(/~/,x)}'
4

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How can awk ignore the field delimiter like comma inside a field?

We have a csv file as mentioned below and the requirement is to change the date format in file as mentioned below. Current file (file.csv) ---------------------- empname,date_of_join,dept,date_of_resignation ram,08/09/2015,sales,21/06/2016 "akash,sahu",08/10/2015,IT,21/07/2016 ... (6 Replies)
Discussion started by: gopal.biswal
6 Replies

2. Shell Programming and Scripting

Replace semicolon within double quotes in a file with semicolon delimiter

Hello Team, Could you please help me with the below question? I have a file with the following properties 1) File Delimiter is ; 2) Text columns are within double quotes 3) Numeric columns will not have double quotes 4) File has total 6 columns Please see a sample record from file ... (3 Replies)
Discussion started by: sam99
3 Replies

3. Shell Programming and Scripting

Extract multiple columns base on double quotes as delimiter

Hi All, I have my data like below "1","abc,db","hac,aron","4","5" Now I need to extract 1,2,4th columns Output should be like "1",abc,db","4" Am trying to use cut command but not able to get the results. Thanks in advance. (4 Replies)
Discussion started by: weknowd
4 Replies

4. 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

5. Shell Programming and Scripting

Ignore delimiter within a column

Hi, So I was trying this awk snippet awk -F, '$1 ~ /Match/' File This is my sample file output Name,Age,Nationality,Description Jack,20,American,Tall, caucasian, lean Mary,30,British,Short,white,slim I would expect expected Output to be, when a certain match is met say $1 is... (2 Replies)
Discussion started by: sidnow
2 Replies

6. 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

7. Shell Programming and Scripting

how to ignore "," between quotes in awk?

Hi, I have file1 where I have my ids and file2 where I have ids and corresponding texts. I have to match the ids of my file1 to file2 and write in ids and corresponding text to another file. e.g file1 ---- 23 1 4 file2 ---- 23,"test, test2" 1,new awk -F, 'BEGIN{FS=","}NR==FNR{ a;next}... (1 Reply)
Discussion started by: babom
1 Replies

8. Shell Programming and Scripting

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 . `grep "14" | cut -d"=" -f2` -F'~'if (NF-1 != v1) ' this command counts number of Tilde... (7 Replies)
Discussion started by: Ganesh Khandare
7 Replies

9. UNIX for Dummies Questions & Answers

Cut a field from a line having quotes as delimiter

Hi , I have extract a single field from the 2nd row of a file of which the format is as given below "Field1","Field2","Field3",...,"Field17",... I need to cut Field17 as such (no quotes required).. I give the command head -2 file_name | tail -1 | cut -d "," -f17 But the output is... (2 Replies)
Discussion started by: nivin_govindan
2 Replies

10. Shell Programming and Scripting

Inserting double quotes after third delimiter

Hi, I'm trying to insert double quotes right after the third delimiter in a file. Delimiter is ^Z. For example: Input: Oct ^Z 1234 ^Z John ^Z Hello!" Desired Output: Oct ^Z 1234 ^Z John ^Z "Hello!" Any ideas? (1 Reply)
Discussion started by: kangaroo
1 Replies
Login or Register to Ask a Question