The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
count occurences of specific character in the file superprogrammer HP-UX 9 04-09-2008 12:05 PM
count character myguess21 Shell Programming and Scripting 13 03-06-2008 03:07 PM
Help On Unix Script Count Line Of File fafo77 Shell Programming and Scripting 4 02-11-2008 07:30 AM
Count occurances of a character in a file Shivdatta Shell Programming and Scripting 6 12-24-2007 04:23 PM
How to count no of occurences of a character in a string in UNIX kamesh83 UNIX for Advanced & Expert Users 11 03-17-2006 02:39 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-07-2007
sethunath sethunath is offline
Registered User
  
 

Join Date: Jun 2007
Location: india
Posts: 5
Unix shll script for character count findings?

Hi,
iam presenting the input text file format.Of this i need the character count of the number of characters present in each file.The attached file is a combination of 3 text file.each text file starts at record 1 - 34, then the next tetx file starts. What i need is the character count of each text file in the main text file.the 3 text file is in a main text file called 71018158.txt.

The first 2 lines of each text file is not required for character count.
I tried the following cmd to remove those 2 line

grep -v "^01" *.txt | wc -m
grep -v "^02" *.txt | wc -m
and i also don't need the " ^ " present in the text file for the determination of the character count.
Hope u understand the point.

Regards
Sethunath







01^V1.0^EXPORTED^2470717800001001001^71018158^00000001^C0^4686019C^AJ82^A457^^n:\indata\20070628\710 18158^71018158.001^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^01^50^01
02^^^71018158^01^01^^^2470717^800001^001^N^^^
03^07611983-01^SAME^^^SAME^^^^^^^^
04^^^^^4616 ^^DE95316^^^95316^^^1^1^Y^Y
05^2^^^^^^^^
06^29633^^^^^^^^^^1
07^061807^061807^11^^90801^^^^^1^ 31000^1^^^^^^00C323001
08^^^^^^^^^^^^^^^^^^
09^^^^^^^^^^^^^^^^^^
10^^^^^^^^^^^^^^^^^^
11^^^^^^^^^^^^^^^^^^
12^^^^^^^^^^^^^^^^^
13^^^^^^^^^^^^^^^^^
14^^^^^^^^^^^^^^^^^
15^^^^^^^^^^^^^^^^^
16^^^^^^^^^^^^^^^^^
17^^^^^^^^^^^^^^^^^
18^^^^^^^^^^^^^^^^^
19^^^^^^^^^^^^^^^^^
20^^^^^^^^^^^^^^^^^
21^^^^^^^^^^^^^^^^^
22^^^^^^^^^^^^^^^^^
23^^^^^^^^^^^^^^^^^
24^^^^^^^^^^^^^^^^^
25^^^^^^^^^^^^^^^^^
26^^^^^^^^^^^^^^^^^
27^^^^^^^^^^^^^^^^^
28^^^^^^^^^^^^^^^^^
29^^^^^^^^^^^^^^^^^
30^^^^^^^^^^^^^^^^^
31^^ 31000
32^Y^^STEWART^^^MD^-0388035^SWART MD^3340 ROAD, D-2^^MO95350^^CA^95350^^^^^^^MD^220 F^^MO95350^MODESTO^CA^95350^^^2095795628^
01232001^
33^^^^^^^^^^071700164-00
34^^^1609987510^1912090622^^1912090622^^2^
01^V1.0^EXPORTED^2470717800002001001^71018158^00000002^C0^4686019C^AJ82^A457^^n:\indata\20070628\710 18158^71018158.002^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^02^50^01
02^^^71018158^01^01^^^2470717^800002^001^N^^^
03^7398347-01^SAME^^^SAME^^^^^^^^
04^^MATTHEW^^^3901 RD^^CE95307^^CA^95307^^11011979^1^1^Y^Y
05^2^^^^^^^^
06^30002^^^^^^^^^^1
07^061807^061807^11^^90807^^^^^1^ 20600^1^^^^^^00C323001
08^^^^^^^^^^^^^^^^^^
09^^^^^^^^^^^^^^^^^^
10^^^^^^^^^^^^^^^^^^
11^^^^^^^^^^^^^^^^^^
12^^^^^^^^^^^^^^^^^
13^^^^^^^^^^^^^^^^^
14^^^^^^^^^^^^^^^^^
15^^^^^^^^^^^^^^^^^
16^^^^^^^^^^^^^^^^^
17^^^^^^^^^^^^^^^^^
18^^^^^^^^^^^^^^^^^
19^^^^^^^^^^^^^^^^^
20^^^^^^^^^^^^^^^^^
21^^^^^^^^^^^^^^^^^
22^^^^^^^^^^^^^^^^^
23^^^^^^^^^^^^^^^^^
24^^^^^^^^^^^^^^^^^
25^^^^^^^^^^^^^^^^^
26^^^^^^^^^^^^^^^^^
27^^^^^^^^^^^^^^^^^
28^^^^^^^^^^^^^^^^^
29^^^^^^^^^^^^^^^^^
30^^^^^^^^^^^^^^^^^
31^^ 20600
32^Y^^STEWART^^^MD^^QUISLING, MD^3340 ROAD, D-2^^MO95350^^CA^95350^^^QUISLING^^^^MD^220 SAVE., #F^^MO95350^^CA^95350^^^209579
5628^05152006^
33^^^^^^^^^^061300348
34^^^1609987510^1912090622^^1912090622^^2^
01^V1.0^EXPORTED^2470717800003001001^71018158^00000003^C0^4686019C^AJ72^A457^NEWHCFA^n:\indata\20070 628\71018158^71018158.003
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^03^50^01
02^^^71018158^01^01^^^2470717^800003^001^N^^^
03^WBW902A68176^SAME^^^SAME^^^^^^^^
04^^JOSEPH^^^907 HELMS ^^MO95350^^CA^95350^^10221946^1^1^^Y
05^2^^^^^^^^
06^29633^^^^^^^^^^1
07^061807^061807^11^^90807^^^^^1^ 20600^1^^^^^^00C323001
08^^^^^^^^^^^^^^^^^^
09^^^^^^^^^^^^^^^^^^
10^^^^^^^^^^^^^^^^^^
11^^^^^^^^^^^^^^^^^^
12^^^^^^^^^^^^^^^^^
13^^^^^^^^^^^^^^^^^
14^^^^^^^^^^^^^^^^^
15^^^^^^^^^^^^^^^^^
16^^^^^^^^^^^^^^^^^
17^^^^^^^^^^^^^^^^^
18^^^^^^^^^^^^^^^^^
19^^^^^^^^^^^^^^^^^
20^^^^^^^^^^^^^^^^^
21^^^^^^^^^^^^^^^^^
22^^^^^^^^^^^^^^^^^
23^^^^^^^^^^^^^^^^^
24^^^^^^^^^^^^^^^^^
25^^^^^^^^^^^^^^^^^
26^^^^^^^^^^^^^^^^^
27^^^^^^^^^^^^^^^^^
28^^^^^^^^^^^^^^^^^
29^^^^^^^^^^^^^^^^^
30^^^^^^^^^^^^^^^^^
31^^ 20600
32^Y^QUISLING^^^^MD^0388035^STEWART^3340 ROAD, D-2^^MO95350^^CA^95350^^^QUISLING^STEWART^^^MD^220 STANDAVE., #F^^^MODESTO^CA^
95350^^^2095795628^05072007^
33^^^^^^^^^^071240677
34^^^1609987510^1912090622^^1912090622^^2^
  #2 (permalink)  
Old 07-07-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,560

Code:
awk 'BEGIN{l=0}
	 NR>2 { 
		  gsub(/\^/,""); 
		  l=l+length(substr($0,3) )	 
	 }
END{print "count: " l}' "file"

  #3 (permalink)  
Old 07-07-2007
drl's Avatar
drl drl is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2007
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 717
Hi.

Here is a non-awk script:

Code:
#!/bin/sh

# @(#) s1       Demonstrate sed manipulation of file for counting.

set -o nounset
echo " sh version: $BASH_VERSION" >&2

FILE=${1-data1}

echo
echo " Characteristics of original file:"
cat $FILE |
wc

echo
echo " File as processed:"
sed  -e '1,2d' -e 's/\^//g' $FILE |
tee t1 |
wc

echo
echo " Edges of file as modified:"
edges -l 2 t1

rm t1

exit 0

running on the first of the files produces:

Code:
% ./s1
 sh version: 2.05b.0(1)-release

 Characteristics of original file:
     36      44    1051

 File as processed:
     34      41     361

 Edges of file as modified:
     1  027101815801012470717800001001N
     2  0307611983-01SAMESAME
   ...
    33  33071700164-00
    34  341609987510191209062219120906

The edges command is local, it prints lines near the beginning and end of a file; it is not necessary to the solution, just a verification of the content of a sample from the modified file.

Keep in mind that the newline character is counted in wc as a character ... cheers, drl
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:29 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0