[NTLUG:Discuss] Bash script help

Fred James fredjame at fredjame.cnc.net
Tue Sep 6 16:01:45 CDT 2011


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
>
> 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.
Daniel
"I am trying to search through some subtitle files for some key words 
and phrases." ...
    grep -in regex *.srt
       -i means ignore case
       -n means show line number in file
       regex is the string you want to find

Alternate ...
    grep -in regex *.srt > newfile.txt

Hope this helps ... or have I missed the point?
Regards
Fred James



More information about the Discuss mailing list