Sponsored Content
Top Forums UNIX for Dummies Questions & Answers How to search and count strings? Post 302864113 by zaxxon on Wednesday 16th of October 2013 02:52:50 AM
Old 10-16-2013
This will show the sum of hits on all lines in the input file:
Code:
$ cat infile
dog cat rat apple banana dog lion tiger dog
cat rat apple banana dog lion tiger dog
lion tiger dog
$ awk '{for(c=0;c<=NF;c++){if($c == "dog"){h++}}} END{print h}' RS= infile
6

This would show it per line:
Code:
$ awk '{for(c=0;c<=NF;c++){if(c==0){h=0}; if($c == "dog"){h++}}} {print h}' infile
3
2
1

This User Gave Thanks to zaxxon For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Count strings on single line?

I use grep -c often, but cannot for the life of me count the number of occurences of a string on the same line (or within a file): $ cat myfile hello457903485897hello 34329048hellojsdfkljlaskdjgh182390 $ grep -c 2 $ How do I count the number of occurences of "hello" in myfile (i.e. 3)?... (6 Replies)
Discussion started by: cs03dmj
6 Replies

2. Shell Programming and Scripting

How to count unique strings

How do I count the total number of unique strings from a file using Perl? Any help is appreciated.. (6 Replies)
Discussion started by: my_Perl
6 Replies

3. Shell Programming and Scripting

count identical strings print last row and count

I have a sorted file like: Apple 3 Apple 5 Apple 8 Banana 2 Banana 3 Grape 31 Orange 7 Orange 13 I'd like to search $1 and if $1 is not the same as $1 in the previous row print that row and print the number of times $1 was found. so the output would look like: Apple 8 3 Banana... (2 Replies)
Discussion started by: dcfargo
2 Replies

4. UNIX for Dummies Questions & Answers

Count the number of strings in a block

Hi, I have the following text in a file: ISA*00* *00* *ZZ*ENS_EDI *ZZ*GATE0215 *110106*2244*U*00401*006224402*1*P*>~ GS*HP*ENS_EDI*GATE0215*20110106*2244*6224402*X*004010X091A1~ ST*835*00006~... (2 Replies)
Discussion started by: donisback
2 Replies

5. Shell Programming and Scripting

Count no of occurrence of the strings based on column value

Can anyone help me to count number of occurrence of the strings based on column value. Say i have 300 files with 1000 record length from which i need to count the number of occurrence string which is existing from 213 to 219. Some may be unique and some may be repeated. (8 Replies)
Discussion started by: zooby
8 Replies

6. Shell Programming and Scripting

How do I count strings on each line?

Hi Im a very inexperienced bioinformatician I have a large DNA file with about 10000 lines of sequence and need to count the occurrence of TA for each line for example in the file TACGCGCGATA TATATATA GGCGCGTATA I would like to get an output like: 2 4 2 I have tried... (3 Replies)
Discussion started by: Manchesterpaul
3 Replies

7. Shell Programming and Scripting

How to count the number of strings?

Hi, I have a text file as shown below. I would like to count the unique number of connections of each person in the first and second column. Third column is the ID numbers of first column persons and fourth column is the ID numbers of second column persons. susan ali 156 294... (7 Replies)
Discussion started by: mohamad
7 Replies

8. Shell Programming and Scripting

Search between two search strings and print the value

Based on the forums i have tried with grep command but i am unable to get the required output. search this value /*------ If that is found then search for temp_vul and print and also search until /*------- and print new_vul Input file contains: ... (5 Replies)
Discussion started by: onesuri
5 Replies

9. Shell Programming and Scripting

Count the number of strings

I have 500 text files in a folder. The data of the text files are shown below. USA Germany 23-12 USA Germany 23-12 USA Germany 23-12 France Germany 15-12 France Germany 15-12 France Italy 25-50 China China 30-32 China China 30-32 I would... (1 Reply)
Discussion started by: sahith
1 Replies

10. Shell Programming and Scripting

Count the occurences of strings

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
expack(1)						      General Commands Manual							 expack(1)

NAME
expack - manipulate Flex files SYNOPSIS
expack -a FLEXFILE FILE... expack -c FLEXFILE FILE... expack -x FLEXFILE [INDEX] expack -i MANIFEST expack -l FLEXFILE DESCRIPTION
expack is a command-line utility that lets you extract and create Flex files. Flex files are archives (which means that they act as con- tainers for other files, somewhat like directories) used by Ultima 7 to store most of its data. Note that the names of the original files are not stored in the Flex -- files are only retrievable by their index. Modes of operation -a Add --NOT IMPLEMENTED YET. FUTURE ENHANCEMENT-- This command adds one or more FILEs to the end of FLEXFILE. -c Create This command takes one or more FILEs and bundles them into FLEXFILE, overwriting it in the process. -x Extract Lets you extract the files contained within FLEXFILE. If INDEX is given only the file at this position will be unpacked, otherwise all files are extracted. The created files will be named index.u7o. -i Input Similar to "Create", this command creates FLEXFILE from a number of input files. However, "Input" takes the names of the input files from MANIFEST instead of the command line. MANIFEST must be a list of file names, one per line. The first name is that of the Flex file that is to be created, the rest are the input files used in building it. -l List This command lists the contents of a FLEXFILE. It gives you the number of files contained within the Flex file, as well as the length of each file. EXAMPLES
expack -a animals.flx bee.wav Adds bee.wav to the Flex file animals.flx. expack -a animals.flx hamster.wav snake.wav donkey.wav Adds hamster.wav, snake.wav, and donkey.wav to the Flex file animals.flx. expack -c animals.flx duck.wav cat.wav cow.wav dog.wav Creates a new Flex file animals.flx containing duck.wav, cat.wav, cow.wav, and dog.wav. expack -x text.flx 17 Extracts the file at position 17fromtext.flxinto17.u7o. expack -x text.flx Extracts all files from text.flx into files named 0.u7o, 1.u7o, 2.u7o, etc. expack -i wavlist With wavlist reading: jmsfx.flx ant.wav bee.wav cat.wav will create a new Flex file jmsfx.flx consisting of ant.wav, bee.wav, andcat.wav. expack -l text.flx Lists the number and lenghts of files contained in text.flx. BUGS
The "Add" command (-a) does not work yet. AUTHOR
This manpage was written by Robert Bihlmeyer based on a text by Marc Winterrowd. It may be freely redistributed and modified under the terms of the GNU General Public License version 2 or higher. Exult 2002-03-23 expack(1)
All times are GMT -4. The time now is 07:11 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy