UNIX c shell script problem!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

UNIX c shell script problem!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Post by cheng » Thu, 17 Oct 1996 04:00:00



Hi,

        I'm recently writing a scrit on searching text, here's the specification:

   The script is invoked with one compulsory and 3 optional parameters:

        MyScript [-n <no.of lines>] <regular expression> [<input file name>] [<output file name>]
        e.g.    MyScript -n 4 "/^astring" ~/fromfile ~/tofile

   The script will search for the string <regular expression> from the input file. And then it will
   output the searched string, the <no. of lines> in front, the <no. of lines> behind to the output file.

   The default setting of [-n <no.of lines>] is 0, i.e. only the mached line will be output.
   The default setting of [<input file name>] is called stdin.
   The default setting of [<output file name>] is called stdout.

   <regular expression> is the compulsory parameter.

   - The output lines cannot duplicate. For example, if there are two matched lines with line number 4
     and 8, and -n 2 is specified, line 6 should only output once.

   - The script should report error when input file specified do not exist and output file specified already
     exists

Here are some questions:

1) How can I use the awk command in this script?

2) How can I identify the parameter $x is the compulsory parameter or not? (Altouguh a " is present for
   that parameter)

3) If the specified line is searched out by the awk, how can I know which line of the file it is in? And
   how can I import the n lines in front and behind from the input file?

4) How can I know the searched line is at end of file (if so?)?

5) How can I know the searched line is at the front of file (if so?)?

6) How can I prevent to output duplicate lines?

Any help are greatly appreciated. Thanx!

Cheers!


 
 
 

UNIX c shell script problem!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Post by Icarus Spar » Fri, 18 Oct 1996 04:00:00




>Hi,

>    I'm recently writing a scrit on searching text, here's the specification:

>   The script is invoked with one compulsory and 3 optional parameters:

>    MyScript [-n <no.of lines>] <regular expression> [<input file name>] [<output file name>]
>    e.g.    MyScript -n 4 "/^astring" ~/fromfile ~/tofile

>   The script will search for the string <regular expression> from the input file. And then it will
>   output the searched string, the <no. of lines> in front, the <no. of lines> behind to the output file.

>   The default setting of [-n <no.of lines>] is 0, i.e. only the mached line will be output.
>   The default setting of [<input file name>] is called stdin.
>   The default setting of [<output file name>] is called stdout.

I would suggest that you do not bother re-inventing the wheel, but instead
look into getting the GNU grep package, which will do almost exactly what
you want.

 
 
 

1. UNIX c shell script problem!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Hi,

        I'm recently writing a scrit on searching text, here's the specification:

   The script is invoked with one compulsory and 3 optional parameters:

        MyScript [-n <no.of lines>] <regular expression> [<input file name>] [<output file name>]
        e.g.    MyScript -n 4 "/^astring" ~/fromfile ~/tofile

   The script will search for the string <regular expression> from the input file. And then it will
   output the searched string, the <no. of lines> in front, the <no. of lines> behind to the output file.

   The default setting of [-n <no.of lines>] is 0, i.e. only the mached line will be output.
   The default setting of [<input file name>] is called stdin.
   The default setting of [<output file name>] is called stdout.

   <regular expression> is the compulsory parameter.

   - The output lines cannot duplicate. For example, if there are two matched lines with line number 4
     and 8, and -n 2 is specified, line 6 should only output once.

   - The script should report error when input file specified do not exist and output file specified already
     exists

Here are some questions:

1) How can I use the awk command in this script?

2) How can I identify the parameter $x is the compulsory parameter or not? (Altouguh a " is present for
   that parameter)

3) If the specified line is searched out by the awk, how can I know which line of the file it is in? And
   how can I import the n lines in front and behind from the input file?

4) How can I know the searched line is at end of file (if so?)?

5) How can I know the searched line is at the front of file (if so?)?

6) How can I prevent to output duplicate lines?

Any help are greatly appreciated. Thanx!

Cheers!


2. ASUS P54TP4 with stealth video DRAM 2M

3. UNIX c shell script problem!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

4. Complex Construct - Can anyone explain?

5. llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll

6. [Q} MTI R407 Motherboard anyone?

7. comp.unix.shell,comp.unix.user-friendly

8. MET DST and MEST

9. P L, PPCQAU7HGUTGG..........................VCCCCCCCCCCCCC AAAAAAAAAAAAAAAAAAAAANNNNNNNNNNNNNNNNNN777777777777777RRRRRRRRRRRRRRRRRBBBBBBBBBBBBBBBBBBBBBBB

10. TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT

11. ? Unix Shell Syntax to log out user from a shell script ?

12. unix shell commands within ftp shell script

13. . sed script unix shell script ispell