[NTLUG:Discuss] Bash script help

Wayne Walker wwalker at solid-constructs.com
Tue Sep 6 16:52:26 CDT 2011


On Tue, Sep 06, 2011 at 04:30:23PM -0400, daniel wrote:
> I am trying to search through some subtitle files for some key words
> and phrases.  They are ASCII test files.  The filenames have spaces
> in them.  The command I am trying is like this:
> 
> for i in *.srt; do echo File: \"$i\" ; cat -n \"$i\" ; done

Not the answer you are looking for, but...

# print the file name and the matching lines
find . -name '*.srt -print0 | xargs -0 egrep -i '(some|key|words|but|no|dirty|ones)'

# print only the file names:
find . -name '*.srt -print0 | xargs -0 egrep -il '(some|key|words|but|no|dirty|ones)'


> The "echo" part works fine.  The "cat" part seems to be breaking up
> the filename by spaces and trying to cat files named by the
> individual parts of the filename delimited by spaces.
> 
> As you can see, I attemtped to fix the problem by enclosing it in
> quotes but it didn't work.  Running the command manually and
> enclosing in quotes works just fine though.
> 
> There is probably a very easy and obvious answer but I'm just not
> getting it.
> 
> 
> 
> _______________________________________________
> http://www.ntlug.org/mailman/listinfo/discuss

-- 

Wayne Walker
wwalker at solid-constructs.com
(512) 633-8076
Senior Consultant
Solid Constructs, LLC



More information about the Discuss mailing list