Awking string only 6 character long and providing a count


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Awking string only 6 character long and providing a count
# 1  
Old 08-17-2012
Awking string only 6 character long and providing a count

Morning Guys,
I am attempting to awk a file which strings in the file is only 6 characters long and not more.

Currently it is counting every line and giving a count of 59, but it should be 57 (not including the long baracode - 004705CIM*****)

Code:
 " awk '/./ {cnt++} END {print cnt}' /tmp/mediacheck"


HTML Code:
[B]Contents of /tmp/mediacheck[/B]
cat /tmp/mediacheck
004705CIMC0XQX
BAE743
BAF061
BAF084
BAF142
BAF054
DVA222
DVA164
DVA067
DVA083
DUY641
DUY674
DVA105
DUY692
BAE745
BAF082
BAF063
BAE767
BAF140
BAF127
BAF173
BAF004
BAF024
BAF032
BAF040
BAE771
CIP386
DVK728
BAF052
DVK779
004705CIMC0W9S
BAB529
MN1257
BAA201
MN1285
DDZ669
MN1276
DGV664
MN1299
MN1338
MN1355
MN1215
BAD100
MN1291
MN1332
MN1196
MN1275
MN1309
MN1385
MN1163
DDZ779
DDZ897
MN1382
MN1281
MN1119
MN1301
MN1312
MN1280
MN1374

Code:
Command run

 awk '/./ {cnt++} END {print cnt}' /tmp/mediacheck
59

# 2  
Old 08-17-2012
Hi

Code:
$ awk 'length<=6{cnt++}END{print cnt}' /tmp/mediacheck
57

Guru.
# 3  
Old 08-17-2012
Code:
grep -Ec '^.{6}$' /tmp/mediacheck

# 4  
Old 08-17-2012
Thanks...

The length entry works, but i also need " /./ " entry, so it ignore EOF entry

e.g
MN1312
MN1280
MN1374
(space and it counted, so i am getting 58 rather 57.)
EOF


Code:
Orginal Syntax
# awk '/./ {cnt++} END {print cnt}' /tmp/mediacheck

Updated Syntax
# awk 'length<=6{cnt++}END{print cnt}' /tmp/mediacheck


Can you help me incorporate the syntax, so i keep EOF synatx and the lenght string also.
# 5  
Old 08-17-2012
Why use awk for such a trivial problem?

For getting count of exactly 6 characters (excluding spaces):
Code:
grep -Ec '^[[:graph:]]{6}$' /tmp/mediacheck

For getting count of 1 to 6 characters (excluding spaces):
Code:
grep -Ec '^[[:graph:]]{1,6}$' /tmp/mediacheck

# 6  
Old 08-17-2012
I have attempted to run your command, but it is failing


Code:
In the Script
TOTAL_MEDIA_REVIEWED=`grep -Ec '^[[:graph:]]{1,6}$' /tmp/mediacheck`


Code:
String Output
+ + grep -Ec ^[[:graph:]]{1,6}$ /tmp/mediacheck
grep: illegal option -- E
Usage: grep -hblcnsviw pattern file . . .

# 7  
Old 08-17-2012
Quote:
Originally Posted by Junes
I have attempted to run your command, but it is failing


Code:
In the Script
TOTAL_MEDIA_REVIEWED=`grep -Ec '^[[:graph:]]{1,6}$' /tmp/mediacheck`


Code:
String Output
+ + grep -Ec ^[[:graph:]]{1,6}$ /tmp/mediacheck
grep: illegal option -- E
Usage: grep -hblcnsviw pattern file . . .

Then try:
Code:
egrep -c '^[[:graph:]]{1,6}$' /tmp/mediacheck

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Count specific character of a file in each line and delete this character in a specific position

I will appreciate if you help me here in this script in Solaris Enviroment. Scenario: i have 2 files : 1) /tmp/TRANSACTIONS_DAILY_20180730.txt: 201807300000000004 201807300000000005 201807300000000006 201807300000000007 201807300000000008 2)... (10 Replies)
Discussion started by: teokon90
10 Replies

2. Shell Programming and Scripting

sed searches a character string for a specified delimiter character, and returns a leading or traili

Hi, Anyone can help using SED searches a character string for a specified delimiter character, and returns a leading or trailing space/blank. Text file : "1"|"ExternalClassDEA519CF5"|"Art1" "2"|"ExternalClass563EA516C"|"Art3" "3"|"ExternalClass305ED16B8"|"Art9" ... ... ... (2 Replies)
Discussion started by: fspalero
2 Replies

3. Shell Programming and Scripting

Finding a certain character in a filename and count the characters up to the certain character

Hello, I do have folders containing having funny strings in their names and one space. First, I do remove the funny strings and replace the space by an underscore. find . -name '* *' | while read file; do target=`echo "$file" | sed 's/... (2 Replies)
Discussion started by: tempestas
2 Replies

4. Shell Programming and Scripting

awk - count character count of fields

Hello All, I got a requirement when I was working with a file. Say the file has unloads of data from a table in the form 1|121|asda|434|thesi|2012|05|24| 1|343|unit|09|best|2012|11|5| I was put into a scenario where I need the field count in all the lines in that file. It was simply... (6 Replies)
Discussion started by: PikK45
6 Replies

5. Shell Programming and Scripting

find 3 character long text

I was trying to do some experiment with "sed". I want to find the filenames which are three characters. So, this is what I have done to search for it, using sed. sed -n -e '/^\{3\}$/p' test This returns the correct output for characters. But if I make change, let's say i create 2 more... (4 Replies)
Discussion started by: aksijain
4 Replies

6. Shell Programming and Scripting

Parsing a long string string problem for procmail

Hi everyone, I am working on fetchmail + procmail to filter mails and I am having problem with parsing a long line in the body of the email. Could anyone help me construct a reg exp for this string below. It needs to match exactly as this string. GetRyt... (4 Replies)
Discussion started by: cwiggler
4 Replies

7. Solaris

Line too long error Replace string with new line line character

I get a file which has all its content in a single row. The file contains xml data containing 3000 records, but all in a single row, making it difficult for Unix to Process the file. I decided to insert a new line character at all occurrences of a particular string in this file (say replacing... (4 Replies)
Discussion started by: ducati
4 Replies

8. Shell Programming and Scripting

awk: sort lines by count of a character or string in a line

I want to sort lines by how many times a string occurs in each line (the most times first). I know how to do this in two passes (add a count field in the first pass then sort on it in the second pass). However, can it be done more optimally with a single AWK command? My AWK has improved... (11 Replies)
Discussion started by: Michael Stora
11 Replies

9. Shell Programming and Scripting

Count number of occurences of a character in a field defined by the character in another field

Hello, I have a text file with n lines in the following format (9 column fields): Example: contig00012 149606 G C 49 68 60 18 c$cccccacccccccccc^c I need to count the number of lower-case and upper-case occurences in column 9, respectively, of the... (3 Replies)
Discussion started by: s052866
3 Replies

10. UNIX for Advanced & Expert Users

How to count no of occurences of a character in a string in UNIX

i have a string like echo "a|b|c" . i want to count the | symbols in this string . how to do this .plz tell the command (11 Replies)
Discussion started by: kamesh83
11 Replies
Login or Register to Ask a Question