[NTLUG:Discuss] Scripting help
Fred James
fredjame at fredjame.cnc.net
Tue Apr 28 09:16:26 CDT 2009
jm wrote:
> i'm not sure of the sequence but i believe your 2nd version would be
> correct ( grep 'the' | wc > thecount.txt )
> once you supply a source file where all the "the's" are stored, such as
>
> grep the <source_file> | wc > thecount.txt
>
> i don't believe the quotes will be necessary
>
>
>
> On Tue, Apr 28, 2009 at 9:34 AM, Dennis Myhand <dmyhand at ednaisd.org> wrote:
>
>> I am trying to show my hardware students some of the things that cane be
>> done from the command line once they get Linux installed on their
>> hardware. I was trying to show how to write a basic bash script that
>> would grep 'the' from a text file, run each instance of 'the' through wc
>> and redirect that output to another file called thecount.txt. I
>> originally thought that:
>>
>> #!/bin/bash
>>
>> grep 'the' > thecount.txt | wc
>>
>> would work, but that does not seem to do the trick. So I changed the
>> order a bit and tried:
>>
>> #!/bin/bash
>>
>> grep 'the' | wc > thecount.txt
>>
>> This does not seem to work either. I remember doing something like this
>> in school (10 years and 3 moves back) but I cannot seem to locate my
>> notes. What am I missing here, besides the notes, I mean? What would
>> be the best way to write this script? Thanks, Dennis in Victoria
>>
>>
Dennis Myhand
Is anywhere near that what you want (see below)?
Regards
Fred James
$ cat fred
The quick brown fox jumped over the lazy dog
$ grep the fred | wc
1 9 45
$ grep -i the fred | wc
1 9 45
$
More information about the Discuss
mailing list