Awk:Find length of string omitting quotes


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Awk:Find length of string omitting quotes
# 1  
Old 05-08-2008
Awk:Find length of string omitting quotes

Hi ,

I have a file named "sample" having the data as follows.

"663005487","USD",0,1,"NR"

If i give like

a=`awk -F ',' '{printf length($2)}' sample`

(Trying to find length of second field)I should get the output for the above as 3 (Omitting double quotes) not 5.

How to do this..

Can anybody help me.

Thanks,
Jayakumar
# 2  
Old 05-08-2008
Code:
a=`awk -F ',' '{gsub("\"", "", $2);printf length($2)}' sample`

Regards
# 3  
Old 05-09-2008
Thanks !!! Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to find and replace Double quotes between pipes

Hello, Need a AWK command to find and replace Double Quotes in Pipe delimited files Actully its a CSV file converted to Pipe but the double quotes still exists. So i want to Get rid of them. Example Input 1|2|3|sadsad|"Abc Efg 3"""|dada Output 1|2|3|sadsad|Abc Efg 3"|dada Thanks... (5 Replies)
Discussion started by: krux_rap
5 Replies

2. Shell Programming and Scripting

awk : match the string and string with the quotes :

Hi all, Here is the data file: - want to match only lan3 in the output . - not lan3:1 file : OPERATING_SYSTEM=HP-UX LOOPBACK_ADDRESS=127.0.0.1 INTERFACE_NAME="lan3" IP_ADDRESS="10.53.52.241" SUBNET_MASK="255.255.255.192" BROADCAST_ADDRESS="" INTERFACE_STATE=""... (2 Replies)
Discussion started by: rveri
2 Replies

3. Shell Programming and Scripting

How to find a string with double quotes?

I have thousands of files in a directory. I need to find/list all files that have the below matching string - RETURNCODE: "1017" Thank you! (5 Replies)
Discussion started by: esmgr
5 Replies

4. Shell Programming and Scripting

Help to find length of string avoiding trailing spaces

Hi, I have a record of length 200 bytes and values filled is only 100 bytes and remaining 100 spaces is occupied by spaces. In script wen i try to find the length of the entire record it should get as 200 not 100. i tried using length and wc -c but it doesnt work can anyone have any idea on... (3 Replies)
Discussion started by: Pranaveen
3 Replies

5. Programming

Fastest way to find the length of string in c

Hi all, We use strlen() fun provided by library to find the length of a string. Looking inside of it, it has some different mechanism to find the length of string. Normally, we scan the string byte by byte until the '\0' character. It takes a logn time to count length. The Library strlen()... (2 Replies)
Discussion started by: yogeshrl9072
2 Replies

6. Programming

How to find length of string and pass into char array in C?

Hi All I want to take a Hexadecimal number as input and i want to find lenth of the input and pass it to char s ( char s ). I have a program to convert hexadecial to binary but it is taking limited input but i want to return binary number based on input. How? (1 Reply)
Discussion started by: atharalikhan
1 Replies

7. Shell Programming and Scripting

how to find the count of commas in a string excluding the ones in double quotes

Hi, my requirement is to find the count of commas in a string excluding the ones in double quotes. For example: If the input string is abc,xyz.com,lmhgdf,"abc, 401 street","tty,stt",45,23,45 The output should be 7 (7 Replies)
Discussion started by: amitshete
7 Replies

8. Shell Programming and Scripting

awk to find the length of each record.

Hi Guys, I wanted to print the length of each record and the record itself. I tried the following awk ... awk 'a=length(); {print $a,$0}' file1 But it is giving me the records instead of length. and also, it giving me each record twice. Means the value of a is not the length of the... (0 Replies)
Discussion started by: mac4rfree
0 Replies

9. UNIX for Dummies Questions & Answers

Read a string with leading spaces and find the length of the string

HI In my script, i am reading the input from the user and want to find the length of the string. The input may contain leading spaces. Right now, when leading spaces are there, they are not counted. Kindly help me My script is like below. I am using the ksh. #!/usr/bin/ksh echo... (2 Replies)
Discussion started by: dayamatrix
2 Replies

10. Shell Programming and Scripting

find the string length in solaris

how to find the string length in solaris machine. (4 Replies)
Discussion started by: din_annauniv
4 Replies
Login or Register to Ask a Question