[PLUG] bash script help

Richard M Lidzbarski (Rick) eikonoklastic at comcast.net
Mon Dec 10 18:18:22 UTC 2007


Robert Citek wrote:
> On Dec 10, 2007 11:54 AM, Richard M Lidzbarski (Rick)
> <eikonoklastic at comcast.net> wrote:
>   
>> I'm stuck. I need to come up with a bash script that does the following:
>> 1)Read a file and extract all sed programs, then:
>> 2)Run the extracted sed programs against a COPY of the original file.
>>
>> Is there a bash script guru that can help? Thanks.
>>     
>
> Can you post an example of the file with sed programs?
>
> Regards,
> - Robert
> _______________________________________________
> PLUG mailing list
> PLUG at lists.pdxlinux.org
> http://lists.pdxlinux.org/mailman/listinfo/plug
>
>   
This is actually a problem for the UNIX class I'm taking. (We're not 
supposed to collaborate with other students on this, but we ARE allowed 
to seek help on the net, etc). Here is the question and the hint 
provided by the instructor.

:QUESTION [40 pts]
      Write a bash script that reads a submission file, extracts all sed
      programs, and then runs the sed program against a COPY of the
      submission file.

HINT
      My bash script uses grep and sed, but awk also could be used.  I use
      the script to process submissions.  In order to simpify this
      question, however, I will make the following unrealistic
      assumptions:

        -All sed commands are one-liners
        -All sed commands start and end with ' and have NO embedded '
         or " characters.
        -All sed commands start at the beginning of a line, and can be
         found with:
               grep -r "^sed[^']*'" | cut -f2 -d"'"
        - The above grep will find ONLY sed commands

          These assumptions are NOT realistic as far as the "real world" but
          should make the script easier to write.  Your script can accept a
          file name on the command line, then create a backup copy.  You 
can use
          the grep command to extract all of the sed programs from the file.
          Think about using a second command file to process the grep 
output.
          To process a file line by line you can use the "read" command.  If
          "myCmd" is the script:
     
      #!/bin/bash
      while read line
      do
        echo "Line: $line"
          done
     
      then you can process a file with the sequence "cat file | myCmd"




More information about the PLUG mailing list