Bourne Shell Script problems
Im trying to make a script that looks for all files in a directo开发者_JAVA技巧ry that ends in .g and then once it finds that file, it will look for "ABCDEFG" in the file.
If the the file has "ABCDEFG" in it, it will display make a note in the file Found only if it does not have "ABCDEFG" already.
This is a practice question for school i just cant get done.
#!/bin/sh
while [grep -l *.g != 0]
file = grep -l *.g
grep -i ‘[ABCDEFG]*$’ /usr/dict/$file
this is where i am stuck.
Try grep -c ABCDEFG *.g | grep ':1$'
As a good starting point to get a list of files that end .* and only have ABC... in it once.
Assign the found file to a variable, then grep it again to see if it contains ABCDEG if true then continue the while loop, if false add the note and continue the loop. Also your missing a done at the end of your while.
You need to take a step back, and read a bit on syntax first.
Try the man pages and help
command.
$ man sh
...
$ man bash
...
$ help while
...
$ help if
...
$ help [
...
use /
to search for a term in the man page.
eg. try PARAMETERS
or CONDITIONAL EXPRESSIONS
etc
精彩评论