Finding the records with a specified length


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding the records with a specified length
# 1  
Old 12-19-2011
Finding the records with a specified length

I have a sample txt file which has different variable lengths of 2,10,3,15.
What is the command that I need use in order to get the record count that has length '3'

Thanks
# 2  
Old 12-19-2011
Code:
awk ' length($0)==3 {cnt++} {next} END {print cnt}' inputfile

one way using awk
# 3  
Old 12-20-2011
Thanx ..dont we have any simple command line utility to demonstrate this..I am trying to use egrep ..but i dun have any idea about the options that needs to be appended with the egrep.

Any help would be really appreciated. Thanks

---------- Post updated at 08:40 AM ---------- Previous update was at 08:38 AM ----------

Quote:
Originally Posted by jim mcnamara
Code:
awk ' length($0)==3 {cnt++} {next} END {print cnt}' inputfile

one way using awk

Sorry to say this but It doesn't yield me anything..Did you provide me the correct syntax..please let me know
# 4  
Old 12-20-2011
Post a sample of your input file.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Finding difference between two columns of unequal length

Hi, I have two files which look like this cat waitstate.txt 18.2 82.1 cat gostate.txt 5.6 5.8 6.1 6.3 6.6 6.9 7.2 7.5 (4 Replies)
Discussion started by: jamie_123
4 Replies

2. Shell Programming and Scripting

Read File and check records for length

I need a script that will run in unix to: 1) Read and input file with 1 column that contains for ex: 0123456789 1234567890 ...etc 2) Checks the first column if it is: a. Numeric from 0 - 9 b. if it is not less... (4 Replies)
Discussion started by: mrn6430
4 Replies

3. Shell Programming and Scripting

Finding the length of the longest column

Hi, I am trying to figure out how to get the length of the longest column in the entire file (because the length varies from one row to the other) I was doing this at first to check how many fields I have for the first row: awk '{print NF; exit}' file Now, I can do this: awk '{ if... (4 Replies)
Discussion started by: MIA651
4 Replies

4. Shell Programming and Scripting

Finding the length of a string in a field

I have a field MPN-BANK-NUMBERO:006,00:N in a file FILE1 How can i display the length of the Bank Number.Any idea ? The output shud take the following format FILE 1 6 Where 1 is the starting position and 6 is the Ending position. (9 Replies)
Discussion started by: bobby1015
9 Replies

5. Shell Programming and Scripting

Unix sort for fixed length columns and records

I was trying to use the AIX 6.1 sort command to sort fixed-length data records, sorting by specific columns only. It took some time to figure out how to get it to work, so I wanted to share the solution. The sort man page wasn't much help, because it talks about field delimeters (default space... (1 Reply)
Discussion started by: CheeseHead1
1 Replies

6. Shell Programming and Scripting

How to reduce the length of records in a file?

I have a file with 400 characters How can I create another file with only a portion of them (like 300 within 400) and get rid of the rest? Thanks (5 Replies)
Discussion started by: fafchi
5 Replies

7. Shell Programming and Scripting

awk to extract incorrect fixed length records

I have a number of unix text files containing fixed-length records (normal unix linefeed terminator) where I need to find odd records which are an incorrect length. The data is not validated and records can contain odd backslash characters and control characters which makes them awkward to process... (2 Replies)
Discussion started by: methyl
2 Replies

8. Shell Programming and Scripting

Using awk to search variable length records

New to awk and need some help. I have a script that I would like to make more compact. I want to read a file and grab every field, from every record, except the last field. The records are variable length and have varying number of fields. A record will have at least two fields, but can have... (9 Replies)
Discussion started by: synergy_texas
9 Replies

9. Shell Programming and Scripting

Help with finding length of a field

I have a pipe delimited file. I need to check that the first and second fields are 5 characters long and if not i need to append 0 in front of them to make them 5 characters long. can some body let mwe know how i can find the length of the two fields and then make them 5 characters long if they... (6 Replies)
Discussion started by: dsravan
6 Replies

10. Shell Programming and Scripting

Fixed Length records- Korne Shell Program.

Hi, I need some help regarding in writing a Korne shell script, in determining the fixed length records in a data file. We have already utility in place, which does this work. The Code for this is as below. In the below $1 is the parameter passed to the script, which is the data file name. ... (4 Replies)
Discussion started by: nrajesh_2009
4 Replies
Login or Register to Ask a Question