08-13-2008
counting a list of string in a list of txt files
Hi there!
I have 150 txt files named chunk1, chunk2, ........., chunk150. I have a second file called string.txt with more than 1000 unique strings, house, dog, cat ... I want to know which command I should use to count how many times each string appears in the 150 files.
I have tried with a grep -c dog chunk* but then I get the count of all of the files and I have to do it separately for each of the strings.
The ideal solution would be an output saying:
dog 45
cat 69
house 92
song 45
Thanks a lot in advance.
Kind regards,
Pep
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
:confused:
I have more than 8000 files in a dir, I need to copy to other dir which containing the "sample"
I tried
grep -il "1189609240791-1268115603299237276@216.109.111.119 ' | cp /tmp/inv
Nothing is happening for long time for 100 file dir too,
Any one can help me? (11 Replies)
Discussion started by: redlotus72
11 Replies
2. Solaris
Dear experts,
In a directory i have both *.TXT and *.txt files. I have a script-
for file in `ls *.txt`; do
mv $file /tmp/$file
How to list both *.txt and*.TXT file in one command so that script will move both .txt or .TXT whatever it find.
br//purple (4 Replies)
Discussion started by: thepurple
4 Replies
3. Shell Programming and Scripting
Hi expersts,
in my directory i have *.txt and *.TXT and *.TXT.log, *.txt.log
I want list only .txt and .TXT files in one command...
how to ??
//purple (1 Reply)
Discussion started by: thepurple
1 Replies
4. UNIX for Dummies Questions & Answers
I have many types of files (Eg: *.log, *.rpt, *.txt, *.dat) in a directory. I want to display all file types except *.txt.
What is the command to display all files except "*.txt" (9 Replies)
Discussion started by: apsprabhu
9 Replies
5. Shell Programming and Scripting
I want to list all the files which are having today's date in its header...
Please let me know if this can be achveived by a single command (8 Replies)
Discussion started by: anandapani
8 Replies
6. Solaris
I want equivalent of ftp in sftp for listing of files into local machine from sftp location.
ftp>ls -l list.txt
the above creates a file list.txt in the local machine's current directory.
sftp>ls -l list.txt
it is giving
Couldn't stat remote file: No such file or directory
is there... (1 Reply)
Discussion started by: megh
1 Replies
7. Shell Programming and Scripting
I am having following folder structure.
/root/audios/pop
/root/audios/jazz
/root/audios/rock
Inside those pop, jazz, rock folders there are following files,
p1.ul, p2.ul, p3.ul, j1.ul, j2.ul, j3.ul, r1.ul, r2.ul, r3.ul
And I have a file named as "audio.txt" in the path /root/audios,... (11 Replies)
Discussion started by: gopikrish81
11 Replies
8. UNIX for Dummies Questions & Answers
I have a string containing fields separated by space
Example
set sr="Fred Ted Joe Peter Paul Jean Chris Tim Tex"
and want to display it in a column format, for example to a maximum
of a window of 100 characters
And hopefully display some thing like
Fred Ted Joe ... (3 Replies)
Discussion started by: kristinu
3 Replies
9. Shell Programming and Scripting
I want to list the name of files with path having perticular string in it.
search must be start from root (/) dir.
Thanks:) (3 Replies)
Discussion started by: anandgodse
3 Replies
10. Shell Programming and Scripting
Hi,
I have a list of zipped files. I want to grep for a string in all files and get a list of file names that contain the string. But without unzipping them before that, more like using something like gzcat.
My OS is:
SunOS test 5.10 Generic_142900-13 sun4u sparc SUNW,SPARC-Enterprise (8 Replies)
Discussion started by: apenkov
8 Replies
LEARN ABOUT CENTOS
perlrequick
PERLREQUICK(1) Perl Programmers Reference Guide PERLREQUICK(1)
NAME
perlrequick - Perl regular expressions quick start
DESCRIPTION
This page covers the very basics of understanding, creating and using regular expressions ('regexes') in Perl.
The Guide
Simple word matching
The simplest regex is simply a word, or more generally, a string of characters. A regex consisting of a word matches any string that
contains that word:
"Hello World" =~ /World/; # matches
In this statement, "World" is a regex and the "//" enclosing "/World/" tells Perl to search a string for a match. The operator "=~"
associates the string with the regex match and produces a true value if the regex matched, or false if the regex did not match. In our
case, "World" matches the second word in "Hello World", so the expression is true. This idea has several variations.
Expressions like this are useful in conditionals:
print "It matches
" if "Hello World" =~ /World/;
The sense of the match can be reversed by using "!~" operator:
print "It doesn't match
" if "Hello World" !~ /World/;
The literal string in the regex can be replaced by a variable:
$greeting = "World";
print "It matches
" if "Hello World" =~ /$greeting/;
If you're matching against $_, the "$_ =~" part can be omitted:
$_ = "Hello World";
print "It matches
" if /World/;
Finally, the "//" default delimiters for a match can be changed to arbitrary delimiters by putting an 'm' out front:
"Hello World" =~ m!World!; # matches, delimited by '!'
"Hello World" =~ m{World}; # matches, note the matching '{}'
"/usr/bin/perl" =~ m"/perl"; # matches after '/usr/bin',
# '/' becomes an ordinary char
Regexes must match a part of the string exactly in order for the statement to be true:
"Hello World" =~ /world/; # doesn't match, case sensitive
"Hello World" =~ /o W/; # matches, ' ' is an ordinary char
"Hello World" =~ /World /; # doesn't match, no ' ' at end
Perl will always match at the earliest possible point in the string:
"Hello World" =~ /o/; # matches 'o' in 'Hello'
"That hat is red" =~ /hat/; # matches 'hat' in 'That'
Not all characters can be used 'as is' in a match. Some characters, called metacharacters, are reserved for use in regex notation. The
metacharacters are
{}[]()^$.|*+?
A metacharacter can be matched by putting a backslash before it:
"2+2=4" =~ /2+2/; # doesn't match, + is a metacharacter
"2+2=4" =~ /2+2/; # matches, + is treated like an ordinary +
'C:WIN32' =~ /C:\WIN/; # matches
"/usr/bin/perl" =~ //usr/bin/perl/; # matches
In the last regex, the forward slash '/' is also backslashed, because it is used to delimit the regex.
Non-printable ASCII characters are represented by escape sequences. Common examples are " " for a tab, "
" for a newline, and "
" for a
carriage return. Arbitrary bytes are represented by octal escape sequences, e.g., "