Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Grep or cat The Whole Directory PROBLEMS :( Post 302934010 by Scrutinizer on Wednesday 4th of February 2015 01:11:41 AM
Old 02-04-2015
With the first approach try:
Code:
find .location -name "*.txt" | while read file; do grep -l '\[' "$file" ; done > grep.txt

or with the second approach ( which which I would expect to be faster )
Code:
find .location -name "*.txt" -exec grep -l '\[' {} + > grep.txt



--
You could also try and see if grep -Fl '[' rather than grep -l '\[' is any faster

Last edited by Scrutinizer; 02-04-2015 at 02:21 AM..
This User Gave Thanks to Scrutinizer For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

variable= 'cat file|wc -l' String problems

Hi, does anybody knows about wc -l, how to transform it inot a just number? this script ALWAYS executes the command3!!, However, the value of BMU_RUNNING is 1 case $BMU_RUNNING in *0) command1 ;; *1) command 2;; *)command 3;; esac The... (3 Replies)
Discussion started by: Santiago
3 Replies

2. UNIX for Advanced & Expert Users

cat and grep not working

I am trying to cat a file and then grep that file for a number. I can do it fine on other files but this particular file will not do anything. I tried running it on an older file from the same device but it is just not working. The file is nothing more than a flat file on a unix box. Here is just a... (3 Replies)
Discussion started by: jphess
3 Replies

3. Shell Programming and Scripting

cat /etc/passwd and grep -v on /etc/shells

Hi All, I'd like to do this cat /etc/passwd and grep -v on the /etc/shells list I'd like to find all shell that doesn't exist on the /etc/passwd. Is there an easy way without doing a egrep -v "/bin/sh|/bin/bash................"? How do I use a file /etc/shells as my list for... (4 Replies)
Discussion started by: itik
4 Replies

4. Shell Programming and Scripting

cat -n and grep

I am not sure if using cat -n is the most efficient way to split a file into multiple files, one file per line in the source file. I thought using cat -n would make it easy to process the file because it produces an output that numbers each line that I could then grep for with the regex "^ *$i".... (3 Replies)
Discussion started by: kapu
3 Replies

5. UNIX for Dummies Questions & Answers

cat a list of directory paths only to a file

Hi! I would like to funnel a series of directories and subdirectories into a text file. This is the output I would like to see from a find command: /mypath/ABC_01/VISIT_01 /mypath/ABC_01/VISIT_02 /mypath/ABC_01/VISIT_03 /mypath/ABC_02/VISIT_01 /mypath/ABC_03/VISIT_01 I've tried: find... (2 Replies)
Discussion started by: goodbenito
2 Replies

6. Shell Programming and Scripting

grep or cat using sed

Is there a way using grep or cat a file to create a new file based on whether the first 9 positions of each record is less than 399999999? This is a fixed file format. (3 Replies)
Discussion started by: ski
3 Replies

7. Shell Programming and Scripting

Problems on cat and substring replacement, shell

Hi I'm new in the Shell world, and I've been trying the whole day to get my script to work. I'm under Ubuntu 10.04. Let me explain: I want to list all the files matching some regex in a directory, and then make some some string replacement on the name of the files, and then a cat on the... (2 Replies)
Discussion started by: albh
2 Replies

8. UNIX for Dummies Questions & Answers

Grep and cat combined

Hello, i need to search one word (snp1) from many files and copy the content of the columns of this word in new file. example: file 1: SNP BP CHR P snp1 1 3 0.01 snp2 2 2 0.05 . . file 2: SNP BP CHR P snp1 1 3 0.06 snp2 2 2 0.3 output... (6 Replies)
Discussion started by: biopsy
6 Replies

9. Shell Programming and Scripting

Problems with using grep to make backups to a different directory

I am trying to program a script that is using grep to find lines in a file in my home directory, and then use a pipe command to copy what is shown into different files in a different directory to create backup files. When I run it, though, it only creates a copy of the file that grep was going... (7 Replies)
Discussion started by: sammythesp3rmy
7 Replies

10. Shell Programming and Scripting

Replace cat and grep with <

Hello someone told me to use OS=`awk '{print int($3)}' < /etc/redhat-release` instead of OS=cat /etc/redhat-release | `awk '{print int($3)}'` any idea for the reason ? (5 Replies)
Discussion started by: nimafire
5 Replies
Mail::Mbox::MessageParser(3pm)				User Contributed Perl Documentation			    Mail::Mbox::MessageParser(3pm)

NAME
Mail::Mbox::MessageParser - A fast and simple mbox folder reader SYNOPSIS
#!/usr/bin/perl use Mail::Mbox::MessageParser; my $file_name = 'mail/saved-mail'; my $file_handle = new FileHandle($file_name); # Set up cache. (Not necessary if enable_cache is false.) Mail::Mbox::MessageParser::SETUP_CACHE( { 'file_name' => '/tmp/cache' } ); my $folder_reader = new Mail::Mbox::MessageParser( { 'file_name' => $file_name, 'file_handle' => $file_handle, 'enable_cache' => 1, 'enable_grep' => 1, } ); die $folder_reader unless ref $folder_reader; # Any newlines or such before the start of the first email my $prologue = $folder_reader->prologue; print $prologue; # This is the main loop. It's executed once for each email while(!$folder_reader->end_of_file()) { my $email = $folder_reader->read_next_email(); print $$email; } DESCRIPTION
This module implements a fast but simple mbox folder reader. One of three implementations (Cache, Grep, Perl) will be used depending on the wishes of the user and the system configuration. The first implementation is a cached-based one which stores email information about mailboxes on the file system. Subsequent accesses will be faster because no analysis of the mailbox will be needed. The second implementation is one based on GNU grep, and is significantly faster than the Perl version for mailboxes which contain very large(10MB) emails. The final implementation is a fast Perl-based one which should always be applicable. The Cache implementation is about 6 times faster than the standard Perl implementation. The Grep implementation is about 4 times faster than the standard Perl implementation. If you have GNU grep, it's best to enable both the Cache and Grep implementations. If the cache information is available, you'll get very fast speeds. Otherwise, you'll take about a 1/3 performance hit when the Grep version is used instead. The overriding requirement for this module is speed. If you wish more sophisticated parsing, use Mail::MboxParser (which is based on this module) or Mail::Box. METHODS AND FUNCTIONS SETUP_CACHE(...) SETUP_CACHE( { 'file_name' => <cache file name> } ); <cache file name> - the file name of the cache Call this function once to set up the cache before creating any parsers. You must provide the location to the cache file. There is no default value. new(...) new( { 'file_name' => <mailbox file name>, 'file_handle' => <mailbox file handle>, 'enable_cache' => <1 or 0>, 'enable_grep' => <1 or 0>, 'force_processing' => <1 or 0>, 'debug' => <1 or 0>, } ); <mailbox file name> - the file name of the mailbox <mailbox file handle> - the already opened file handle for the mailbox <enable_cache> - true to attempt to use the cache implementation <enable_grep> - true to attempt to use the grep implementation <force_processing> - true to force processing of files that look invalid <debug> - true to print some debugging information to STDERR The constructor takes either a file name or a file handle, or both. If the file handle is not defined, Mail::Mbox::MessageParser will attempt to open the file using the file name. You should always pass the file name if you have it, so that the parser can cache the mailbox information. This module will automatically decompress the mailbox as necessary. If a filename is available but the file handle is undef, the module will call either bzip2, or gzip to decompress the file in memory if the filename ends with .tz, .bz2, or .gz, respectively. If the file handle is defined, it will detect the type of compression and apply the correct decompression program. The Cache, Grep, or Perl implementation of the parser will be loaded, whichever is most appropriate. For example, the first time you use caching, there will be no cache. In this case, the grep implementation can be used instead. The cache will be updated in memory as the grep implementation parses the mailbox, and the cache will be written after the program exits. The file name is optional, in which case enable_cache and enable_grep must both be false. force_processing will cause the module to process folders that look to be binary, or whose text data doesn't look like a mailbox. Returns a reference to a Mail::Mbox::MessageParser object on success, and a scalar desribing an error on failure. ("Not a mailbox", "Can't open <filename>: <system error>", "Can't execute <uncompress command> for file <filename>" reset() Reset the filehandle and all internal state. Note that this will not work with filehandles which are streams. If there is enough demand, I may add the ability to store the previously read stream data internally so that reset() will work correctly. endline() Returns " " or " ", depending on the file format. prologue() Returns any newlines or other content at the start of the mailbox prior to the first email. end_of_file() Returns true if the end of the file has been encountered. line_number() Returns the line number for the start of the last email read. number() Returns the number of the last email read. (i.e. The first email will have a number of 1.) length() Returns the length of the last email read. offset() Returns the byte offset of the last email read. read_next_email() Returns a reference to a scalar holding the text of the next email in the mailbox, or undef at the end of the file. BUGS
No known bugs. Contact david@coppit.org for bug reports and suggestions. AUTHOR
David Coppit <david@coppit.org>. LICENSE
This software is distributed under the terms of the GPL. See the file "LICENSE" for more information. HISTORY
This code was originally part of the grepmail distribution. See http://grepmail.sf.net/ for previous versions of grepmail which included early versions of this code. SEE ALSO
Mail::MboxParser, Mail::Box perl v5.10.1 2010-06-06 Mail::Mbox::MessageParser(3pm)
All times are GMT -4. The time now is 06:12 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy