04-20-2007
grep and count no of occurences in every line of a file
Hi Folks,
I have a input file of the below format.
~~~OLKIT~OLKIT~1~~TBD~BEST PAGER & WIRELESS~4899 COMMON MARKET PLACE~~~DUBLIN~KS~43016~I~Y~DIRECT~D~~0
BPGRWRLS~~~OLKIT~OLKIT~1~~TBD~BEST PAGER & WIRELESS~4899 COMMON MARKET PLACE~~~DUBLIN~KS~43016~I~Y~DIRECT~D~~0
BPI~~~OLKIT~OLKIT~1~~TBD~CITI CONNECTION~6413 18TH AVE~~~BROOKLYN~KS~11204~~Y~DIRECT~D~~0
BPNABOF~~~OLKIT~OLKIT~1~~TBD~BRIGHTPOINT NORTH AMERICA~501 AIRTECH PARKWAY~~~PLAINFIELD~KS~46168~~Y~DIRECT~DT~~0
BRADSINC~~~OLKIT~OLKIT~1~~TBD~BRADSHAW INC~4662 HORN LAKE RD~~~MEMPHIS~KS~38109~I~Y~DIRECT~D~~0
BWRES07TM~~~OLKIT~OLKIT~1~~TBD~BLUEFISH WIRELESS INC.~6100 WEST 96TH ST., SUITE 140~~~INDIANAPOLIS~KS~46278~~Y~DIRECT~J~~0
BYFGRPTM~~~OLKIT~OLKIT~1~~TBD~BYF GROUP, INC.~4810 BEAUREGARD ST.~~~ALEXANDRIA~KS~22312~~Y~DIRECT~F~~0
In the input file I have many no of lines which have "~" symbols in them.
In every line, I need to count the no. of times "~" occurs and compare it with a variable which is passed along with the shell script in the command line.
I have highlited each line in diffn color.
The command line format is
shell_script input_file.dat 20
In the above line 20 is the no to which the no of "~" are compared
Help is very much required as I am very new into shell scripting.
Regards
Srikanth GR
Last edited by srikanthgr1; 04-20-2007 at 06:30 AM..
Reason: Needed to give more details.
10 More Discussions You Might Find Interesting
1. HP-UX
For counting the occurences of specific character in the file
I am issuing the command
grep -o 'character' filename | wc -w
It works in other shells but not in HP-UX as there is no option -o for grep.
What do I do now? (9 Replies)
Discussion started by: superprogrammer
9 Replies
2. UNIX for Dummies Questions & Answers
Hello,
I want to count the occurences of a specific word in a .txt file in bash shell.
Can somebody help me pleaze??
Thanks!!! (2 Replies)
Discussion started by: mskart
2 Replies
3. Shell Programming and Scripting
Hi,
i am in need of an awk script to accomplish the following:
Input table looks like:
Student1 arts
Student2 science
Student3 arts
Student4 science
Student5 science
Student6 science
Student7 science
Student8 science
Student9 science
Student10 science
Student11 science... (8 Replies)
Discussion started by: saint2006
8 Replies
4. Shell Programming and Scripting
We have a log file, the format is similar to this:
08/04/2011 05:03:08 Connection Success
08/04/2011 05:13:18 Connection Success
08/04/2011 05:23:28 Connection Fail
08/04/2011 05:33:38 Connection Success
08/04/2011 06:14:18 Connection Success
08/04/2011 06:24:28 Connection Fail
08/04/2011... (6 Replies)
Discussion started by: clu
6 Replies
5. Shell Programming and Scripting
Hi,
Please help me in finding the number of occurences of the string.
Example: Apple, green, blue, Apple, Orange, green, blue are the strings can be even in the next line.
The o/p should look as:
Word Count
----- -----
Apple 2
green 2
Orange 1
blue 2
Thanks (2 Replies)
Discussion started by: acc888
2 Replies
6. UNIX for Dummies Questions & Answers
hi,
I have a text..and i need to find a pattern in the text and count to the no of times the pattern occured.
i have used grep command ..but the problem is , it shows the occurrences of the pattern but doesn't count no of times the pattern occuries. (5 Replies)
Discussion started by: nvnni
5 Replies
7. Shell Programming and Scripting
Anyone knows how to use AWK to achieve the following
Sun Feb 12 00:41:01-00:41:59 Success:2 Fail:2
Sun Feb 12 00:42:01-00:42:59 Success:1 Fail:2
Sun Feb 12 01:20:01-01:20:59 Success:1 Fail:2
Mon Feb 13 22:41:01-22:41:59 Success:1 Fail:1
log file:
Success
Success
Fail
Fail
... (9 Replies)
Discussion started by: timmywong
9 Replies
8. Shell Programming and Scripting
Hi,
I have a file while is the output of lspath command and output of file is
#cat lspath.txt
Enabled hdisk0 vscsi0
Enabled hdisk0 vscsi1
Enabled hdisk1 vscsi0
Enabled hdisk2 vscsi0
Enabled hdisk2 vscsi1
Missing hdisk3 vscsi0
Enabled hdisk3 vscsi1
Have created script to check state... (7 Replies)
Discussion started by: ksgnathan
7 Replies
9. Shell Programming and Scripting
I have some text files in a folder f1 with 10 columns. The first five columns of a file are shown below.
aab abb 263-455 263 455
aab abb 263-455 263 455
aab abb 263-455 263 455
bbb abb 26-455 26 455
bbb abb 26-455 26 455
bbb aka 264-266 264 266
bga bga 230-232 230 ... (10 Replies)
Discussion started by: gomez
10 Replies
10. Shell Programming and Scripting
Hello,
I try to sort results of occurences in an array by using awk but I can't find the right command. that's why I'm asking your help ! :)
Please see below the command that I run:
awk '{ for ( i=1; i<=length; i++ ) arr++ }END{ for ( i in arr ) { print i, arr } }' dictionnary.txt
... (3 Replies)
Discussion started by: destin45
3 Replies
MSGS(1) BSD General Commands Manual MSGS(1)
NAME
msgs -- system messages and junk mail program
SYNOPSIS
msgs [-fhlpqr] [number] [-number]
msgs [-s]
msgs [-c [days]]
DESCRIPTION
msgs is used to read system messages. These messages are sent by mailing to the login `msgs' and should be short pieces of information which
are suitable to be read once by most users of the system.
msgs is normally invoked each time you login, by placing it in the file .login (or .profile if you use sh(1)). It will then prompt you with
the source and subject of each new message. If there is no subject line, the first few non-blank lines of the message will be displayed. If
there is more to the message, you will be told how long it is and asked whether you wish to see the rest of the message. The possible
responses are:
y Type the rest of the message.
RETURN Synonym for y.
n Skip this message and go on to the next message.
- Redisplay the last message.
q Drop out of msgs; the next time msgs will pick up where it last left off.
s Append the current message to the file ``Messages'' in the current directory; `s-' will save the previously displayed message. A
`s' or `s-' may be followed by a space and a file name to receive the message replacing the default ``Messages''.
m A copy of the specified message is placed in a temporary mailbox and mail(1) is invoked on that mailbox.
p The specified message is piped through PAGER, or, if PAGER is null or not defined, more(1). The commands `m', `p', and `s' all
accept a numeric argument in place of the `-'.
msgs keeps track of the next message you will see by a number in the file .msgsrc in your home directory. In the directory /var/msgs it
keeps a set of files whose names are the (sequential) numbers of the messages they represent. The file /var/msgs/bounds shows the low and
high number of the messages in the directory so that msgs can quickly determine if there are no messages for you. If the contents of bounds
is incorrect it can be fixed by removing it; msgs will make a new bounds file the next time it is run.
The -s option is used for setting up the posting of messages. The line
msgs: "| /usr/bin/msgs -s"
should be included in /etc/mail/aliases (see newaliases(1)) to enable posting of messages.
The -c option is used for performing cleanup on /var/msgs. An entry with the -c option should be placed in /etc/crontab to run every night.
This will remove all messages over 21 days old. A different expiration may be specified on the command line to override the default.
Options when reading messages include:
-f Do not print ``No new messages.''. This is useful in a .login file since this is often the case here.
-q Queries whether there are messages, printing ``There are new messages.'' if there are. The command ``msgs -q'' is often used in
login scripts.
-h Print the first part of messages only.
-r Disables the ability to save messages or enter the mailer. It is assumed that PAGER is set to something secure.
-l Option causes only locally originated messages to be reported.
number A message number can be given on the command line, causing msgs to start at the specified message rather than at the next message
indicated by your .msgsrc file. Thus
msgs -h 1
prints the first part of all messages.
-number Start number messages back from the one indicated in the .msgsrc file, useful for reviews of recent messages.
-p Pipe long messages through PAGER, or, if PAGER is null or not defined, more(1).
Within msgs you can also go to any specific message by typing its number when msgs requests input as to what to do.
ENVIRONMENT
msgs uses the HOME and TERM environment variables for the default home directory and terminal type.
FILES
/var/msgs/* database
~/.msgsrc number of next message to be presented
SEE ALSO
mail(1), more(1), aliases(5)
HISTORY
The msgs command appeared in 3.0BSD.
BSD
April 28, 1995 BSD