Help required for counting delimiter


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help required for counting delimiter
# 1  
Old 04-24-2008
Help required for counting delimiter

Hi All,

I have a delimited file.Sometime it happens that delimiter get missed between 2 fields,so i need to count the number of delimiter present at each line.
exam
file.txt
a|b|c|d
e|f|a
cc|dd

so output should be
1 3
2 2
3 1

Thanks
# 2  
Old 04-24-2008
Addressed here
# 3  
Old 04-24-2008
Hi,

awk -F"|" '{ print NR,NF-1}' file.txt

Thanks
--penchal
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl Code to change file delimiter (passed as argument) to bar delimiter

Hi, Extremely new to Perl scripting, but need a quick fix without using TEXT::CSV I need to read in a file, pass any delimiter as an argument, and convert it to bar delimited on the output. In addition, enclose fields within double quotes in case of any embedded delimiters. Any help would... (2 Replies)
Discussion started by: JPB1977
2 Replies

2. Shell Programming and Scripting

Shell script to put delimiter for a no delimiter variable length text file

Hi, I have a No Delimiter variable length text file with following schema - Column Name Data length Firstname 5 Lastname 5 age 3 phoneno1 10 phoneno2 10 phoneno3 10 sample data - ... (16 Replies)
Discussion started by: Gaurav Martha
16 Replies

3. Shell Programming and Scripting

How to cut by delimiter, and delimiter can be anything except numbers?

Hi all, I have a number of strings like below: //mnt/autocor/43°13'(33")W/ and i'm trying to get the numbers in this string, for example 431333 please help thanks ahead (14 Replies)
Discussion started by: sunnydanniel
14 Replies

4. UNIX for Dummies Questions & Answers

counting?

Hi all, I promise this is my very last dumb question.. but how to you count how many unique names you have. My dataset is: >Bac1 afdsgrr >Bac4 egege >Bac8 dgrjh >Bac1 afdsgrr >Bac1 afdsgrr >Bac8 dgrjh What i want to know is that how many unique names there is, so the output would... (3 Replies)
Discussion started by: Iifa
3 Replies

5. Shell Programming and Scripting

Counting number of records with string row delimiter

HI, i have a file like this t.txt f1|_f2|_ f1|_f2|_ f1|_f2|_ as if col delimiter is |_ and row delimiter |_\n trying to count number of records using awk $ awk 'BEGIN{FS="|_" ; RS="~~\n"} {n++}END{print n} ' t.txt 7 wondering how can i count this to 3 ? thx (9 Replies)
Discussion started by: aksforum
9 Replies

6. Shell Programming and Scripting

Help- counting delimiter in a huge file and split data into 2 files

I’m new to Linux script and not sure how to filter out bad records from huge flat files (over 1.3GB each). The delimiter is a semi colon “;” Here is the sample of 5 lines in the file: Name1;phone1;address1;city1;state1;zipcode1 Name2;phone2;address2;city2;state2;zipcode2;comment... (7 Replies)
Discussion started by: lv99
7 Replies

7. Shell Programming and Scripting

Counting

Hi, The following output shows how many pmon process are started by users named : oracle or yoavb $ ps -ef |grep pmon |grep -v grep |grep -v ipmon oracle 11268 1 0 Sep 2 ? 36:00 ora_pmon_qerp oracle 17496 1 0 Oct 11 ? 8:58 ora_pmon_bcv oracle 15081 1 0 ... (5 Replies)
Discussion started by: yoavbe
5 Replies

8. Shell Programming and Scripting

Substring based on delimiter, finding last delimiter

Hi, I have a string like ABC.123.XYZ-A1-B2-P1-C4. I want to delimit the string based on "-" and then get result as only two strings. One with string till last hyphen and other with value after last hyphen... For this case, it would be something like first string as "ABC.123.XYZ-A1-B2-P1" and... (6 Replies)
Discussion started by: gupt_ash
6 Replies

9. Shell Programming and Scripting

Counting

Hi, I want to count how many rows are in a file for a specific column. eg. K NM K NM K NM K JK K NM K JK K NM so the file is tab-delimited. I want to count how many rows are in column 2 and how many NMs there are. I used awk awk '{OFS="\t"}; {count++} {print i,... (3 Replies)
Discussion started by: phil_heath
3 Replies

10. Shell Programming and Scripting

Getting required fields from a test file in required fromat in unix

My data is something like shown below. date1 date2 aaa bbbb ccccc date3 date4 dddd eeeeeee ffffffffff ggggg hh I want the output like this date1date2 aaa eeeeee I serached in the forum but didn't find the exact matching solution. Please help. (7 Replies)
Discussion started by: rdhanek
7 Replies
Login or Register to Ask a Question