Sponsored Content
Top Forums Shell Programming and Scripting number of occurences of a string Post 302098393 by siddu_chittari on Monday 4th of December 2006 02:50:59 AM
Old 12-04-2006
hi srikanth,

This gives me the number of fields in each line of my file but my requirement is different

for ex) let usa ssume my file like this

nasa isro nasa
nasa nasa isro
isro nasa nasa

now i want to count all occurences of 'nasa' in the above file

'grep' is not a proper option coz it always gives the number of lines that the string 'nasa' is present in the file
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Counting number of occurences

Hi All, I have to count the number of occurences of the character " ; " in a given line. I had used the following awk command to achieve the same echo $KOP.dat|awk '{split($1,my,";"); for(i in my)c++ }END{print c-1}' My file KOP.dat had the following data ... (1 Reply)
Discussion started by: kingofprussia
1 Replies

2. Shell Programming and Scripting

How to count the number of occurences of this pattern?

Hi all, I have a pattern like this in a file: 123 4 56 789 234 5 67 789 121 3 56 789 222 4 65 789 321 6 90 100 478 8 40 789 243 7 80 789 How can I count the number of occurences of '789' (4th column) in this set...? Thanks for all your help! K (7 Replies)
Discussion started by: kripssmart
7 Replies

3. Shell Programming and Scripting

counting the number of occurences

say i've got a text file with >10million sequences: ssss ssss tttttt uuuuuu uuuuuu uuuuuu ... I'd like to convert the file so that the output will report the number of occurence right by each sequence: 2 ssss 2 ssss 1 tttttt 3 uuuuuu 3 uuuuuu 3 uuuuuu .... (3 Replies)
Discussion started by: johjoh
3 Replies

4. UNIX for Dummies Questions & Answers

Count number of occurences of a word

I want to count the number of occurences of say "200" in a file but that file also contains various stuff including dtaes like 2007 or smtg like 200.1 so count i am getting by doing grep -c "word" file is wrong Please help!!!!! (8 Replies)
Discussion started by: shikhakaul
8 Replies

5. Shell Programming and Scripting

awk counting number of occurences

Hi, I am trying to count the max number of occurences of field1 in my apache log example: 10.0.0.1 field2 field3 10.0.0.2 filed2 field3 10.0.0.1 field2 field3 10.0.0.1 field2 field3 awk result to print out only the most occurence of field1 and number of occurence and field1 is... (3 Replies)
Discussion started by: phamp008
3 Replies

6. Shell Programming and Scripting

to count the number of occurences of a column value

im trying to count the number of occurences of column 2 value(starting from KKK*) of the below file, file.txt using the code cat file.txt | awk ' BEGIN { print "Category Counts"} {FS=","} {NR > 2} { cats = cats + 1} END { for(c in cats) { print c, "=", cats} } ' but its returning as ... (6 Replies)
Discussion started by: michaelrozar17
6 Replies

7. UNIX for Dummies Questions & Answers

Number of word occurences in a file?

Hello world, Can anybody tell me how to count how many times does a word repeat in a file? There have been many threads on this but they all are heavy loads of Scripting for a starter like me. :D So, I sat down today and after some hours of reading man pages, I found a simple one-line... (18 Replies)
Discussion started by: satish51392111
18 Replies

8. Shell Programming and Scripting

Count number of occurences using awk

Hi Guys, I have 2 files like below file1 xx yy file2 b yy b2 xx c1 yy xx yy Now I want an idea which can count occurences of text from file1 and file2 so outbout would be kind of (9 Replies)
Discussion started by: prashant2507198
9 Replies

9. Shell Programming and Scripting

Count and print the number of occurences

I have some files as shown below GLL ALM 654-656 654 656 SEM LYG 655-657 655 657 SEM LYG 655-657 655 657 ALM LEG 656-658 656 658 ALM LEG 656-658 656 658 ALM LEG 656-658 656 658 LEG LEG 658-660 658 660 LEG LEG 658-660 658 660 The value of GLL is... (5 Replies)
Discussion started by: arch
5 Replies

10. Shell Programming and Scripting

Number of Consecutive Occurences

:b: Hi Folks, I have a requirement to find the number of consecutive occurences based on month. Here is the below sample of my requirement. I have say four columns CARUSERNAME BRAND_CODE MONTH YEAR Below is sample Data John|C|JAN|2013 Tim|C|FEB|2013 Tom|C|Mar|2013 Ron|C|Apr|2013... (4 Replies)
Discussion started by: dinesh1985
4 Replies
Template::Plugin::String(3)				User Contributed Perl Documentation			       Template::Plugin::String(3)

NAME
Template::Plugin::String - Object oriented interface for string manipulation SYNOPSIS
# create String objects via USE directive [% USE String %] [% USE String 'initial text' %] [% USE String text => 'initial text' %] # or from an existing String via new() [% newstring = String.new %] [% newstring = String.new('newstring text') %] [% newstring = String.new( text => 'newstring text' ) %] # or from an existing String via copy() [% newstring = String.copy %] # append text to string [% String.append('text to append') %] # format left, right or center/centre padded [% String.left(20) %] [% String.right(20) %] [% String.center(20) %] # American spelling [% String.centre(20) %] # European spelling # and various other methods... DESCRIPTION
This module implements a "String" class for doing stringy things to text in an object-oriented way. You can create a "String" object via the "USE" directive, adding any initial text value as an argument or as the named parameter "text". [% USE String %] [% USE String 'initial text' %] [% USE String text='initial text' %] The object created will be referenced as "String" by default, but you can provide a different variable name for the object to be assigned to: [% USE greeting = String 'Hello World' %] Once you've got a "String" object, you can use it as a prototype to create other "String" objects with the "new()" method. [% USE String %] [% greeting = String.new('Hello World') %] The "new()" method also accepts an initial text string as an argument or the named parameter "text". [% greeting = String.new( text => 'Hello World' ) %] You can also call "copy()" to create a new "String" as a copy of the original. [% greet2 = greeting.copy %] The "String" object has a "text()" method to return the content of the string. [% greeting.text %] However, it is sufficient to simply print the string and let the overloaded stringification operator call the "text()" method automatically for you. [% greeting %] Thus, you can treat "String" objects pretty much like any regular piece of text, interpolating it into other strings, for example: [% msg = "It printed '$greeting' and then dumped core " %] You also have the benefit of numerous other methods for manipulating the string. [% msg.append("PS Don't eat the yellow snow") %] Note that all methods operate on and mutate the contents of the string itself. If you want to operate on a copy of the string then simply take a copy first: [% msg.copy.append("PS Don't eat the yellow snow") %] These methods return a reference to the "String" object itself. This allows you to chain multiple methods together. [% msg.copy.append('foo').right(72) %] It also means that in the above examples, the "String" is returned which causes the "text()" method to be called, which results in the new value of the string being printed. To suppress printing of the string, you can use the "CALL" directive. [% foo = String.new('foo') %] [% foo.append('bar') %] # prints "foobar" [% CALL foo.append('bar') %] # nothing CONSTRUCTOR METHODS
These methods are used to create new "String" objects. new() Creates a new string using an initial value passed as a positional argument or the named parameter "text". [% USE String %] [% msg = String.new('Hello World') %] [% msg = String.new( text => 'Hello World' ) %] copy() Creates a new "String" object which contains a copy of the original string. [% msg2 = msg.copy %] INSPECTOR METHODS
These methods are used to examine the string. text() Returns the internal text value of the string. The stringification operator is overloaded to call this method. Thus the following are equivalent: [% msg.text %] [% msg %] length() Returns the length of the string. [% USE String("foo") %] [% String.length %] # => 3 search($pattern) Searches the string for the regular expression specified in $pattern returning true if found or false otherwise. [% item = String.new('foo bar baz wiz waz woz') %] [% item.search('wiz') ? 'WIZZY! :-)' : 'not wizzy :-(' %] split($pattern, $limit) Splits the string based on the delimiter $pattern and optional $limit. Delegates to Perl's internal "split()" so the parameters are exactly the same. [% FOREACH item.split %] ... [% END %] [% FOREACH item.split('baz|waz') %] ... [% END %] MUTATOR METHODS
These methods modify the internal value of the string. For example: [% USE str=String('foobar') %] [% str.append('.html') %] # str => 'foobar.html' The value of "str" is now '"foobar.html"'. If you don't want to modify the string then simply take a copy first. [% str.copy.append('.html') %] These methods all return a reference to the "String" object itself. This has two important benefits. The first is that when used as above, the "String" object '"str"' returned by the "append()" method will be stringified with a call to its "text()" method. This will return the newly modified string content. In other words, a directive like: [% str.append('.html') %] will update the string and also print the new value. If you just want to update the string but not print the new value then use "CALL". [% CALL str.append('.html') %] The other benefit of these methods returning a reference to the "String" is that you can chain as many different method calls together as you like. For example: [% String.append('.html').trim.format(href) %] Here are the methods: push($suffix, ...) / append($suffix, ...) Appends all arguments to the end of the string. The "append()" method is provided as an alias for "push()". [% msg.push('foo', 'bar') %] [% msg.append('foo', 'bar') %] pop($suffix) Removes the suffix passed as an argument from the end of the String. [% USE String 'foo bar' %] [% String.pop(' bar') %] # => 'foo' unshift($prefix, ...) / prepend($prefix, ...) Prepends all arguments to the beginning of the string. The "prepend()" method is provided as an alias for "unshift()". [% msg.unshift('foo ', 'bar ') %] [% msg.prepend('foo ', 'bar ') %] shift($prefix) Removes the prefix passed as an argument from the start of the String. [% USE String 'foo bar' %] [% String.shift('foo ') %] # => 'bar' left($pad) If the length of the string is less than $pad then the string is left formatted and padded with spaces to $pad length. [% msg.left(20) %] right($pad) As per left() but right padding the "String" to a length of $pad. [% msg.right(20) %] center($pad) / centre($pad) As per left() and right() but formatting the "String" to be centered within a space padded string of length $pad. The "centre()" method is provided as an alias for "center()". [% msg.center(20) %] # American spelling [% msg.centre(20) %] # European spelling format($format) Apply a format in the style of "sprintf()" to the string. [% USE String("world") %] [% String.format("Hello %s ") %] # => "Hello World " upper() Converts the string to upper case. [% USE String("foo") %] [% String.upper %] # => 'FOO' lower() Converts the string to lower case [% USE String("FOO") %] [% String.lower %] # => 'foo' capital() Converts the first character of the string to upper case. [% USE String("foo") %] [% String.capital %] # => 'Foo' The remainder of the string is left untouched. To force the string to be all lower case with only the first letter capitalised, you can do something like this: [% USE String("FOO") %] [% String.lower.capital %] # => 'Foo' chop() Removes the last character from the string. [% USE String("foop") %] [% String.chop %] # => 'foo' chomp() Removes the trailing newline from the string. [% USE String("foo ") %] [% String.chomp %] # => 'foo' trim() Removes all leading and trailing whitespace from the string [% USE String(" foo ") %] [% String.trim %] # => 'foo' collapse() Removes all leading and trailing whitespace and collapses any sequences of multiple whitespace to a single space. [% USE String(" foo bar ") %] [% String.collapse %] # => "foo bar" truncate($length, $suffix) Truncates the string to $length characters. [% USE String('long string') %] [% String.truncate(4) %] # => 'long' If $suffix is specified then it will be appended to the truncated string. In this case, the string will be further shortened by the length of the suffix to ensure that the newly constructed string complete with suffix is exactly $length characters long. [% USE msg = String('Hello World') %] [% msg.truncate(8, '...') %] # => 'Hello...' replace($search, $replace) Replaces all occurences of $search in the string with $replace. [% USE String('foo bar foo baz') %] [% String.replace('foo', 'wiz') %] # => 'wiz bar wiz baz' remove($search) Remove all occurences of $search in the string. [% USE String('foo bar foo baz') %] [% String.remove('foo ') %] # => 'bar baz' repeat($count) Repeats the string $count times. [% USE String('foo ') %] [% String.repeat(3) %] # => 'foo foo foo ' AUTHOR
Andy Wardley <abw@wardley.org> <http://wardley.org/> COPYRIGHT
Copyright (C) 1996-2007 Andy Wardley. All Rights Reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. SEE ALSO
Template::Plugin perl v5.16.3 2011-12-20 Template::Plugin::String(3)
All times are GMT -4. The time now is 04:41 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy