You are not logged in.

#1 2008-12-04 03:06:53

oxoxo
Member
Registered: 2008-10-31
Posts: 66

Complex Control Statements

I want my program to accept two arguments, So im wondering how to do this.

#!/bin/bash

for FILE in ""    #<-- need a for loop or some way to accept up to 2 arguments.
do
          while read MyLine
          do
          if [[ "$MyLine" =~ "sed -n  '/printregex/,/to this regex/{/but not this
          regex/d;p}' | sed -n '/---/,+3!p' | sed -n '/#/!p' | sed 's/^[ ]*//'
          | sed -e s/[^:]*://" ]]; then
                              tmp=$(echo $MyLine)
         fi
                while read MyLine2
                do
                     if [[ "$MyLine2" =~ "sed -n '/regex/,/to regex/{/but not including this regex/d;p}'
                    | sed - n '/#/!p | sed -e s/[^:]*// | sed /---------------/,+10d ]]; then
                           tmp2=$(echo $MyLine)
                     fi

done > $FILE
done > $FILE
done

I think the sed regex's are fine. This is not my exact script, but the one im executing yeilds a blank line, i think i might be outputting something wrong..

Offline

#2 2008-12-04 03:36:45

Daenyth
Forum Fellow
From: Boston, MA
Registered: 2008-02-24
Posts: 1,244

Re: Complex Control Statements

Look into using getopt. Also the case statement.

Offline

#3 2008-12-04 03:48:36

oxoxo
Member
Registered: 2008-10-31
Posts: 66

Re: Complex Control Statements

Well i might want to open the file with the if statements, and then use, Var1=$(echo $MyLine | sed - n ... )

Last edited by oxoxo (2008-12-04 03:49:38)

Offline

#4 2008-12-04 06:41:11

oxoxo
Member
Registered: 2008-10-31
Posts: 66

Re: Complex Control Statements

to read a line in my file:

if [[ "$line" =~ ^regex ]];

Which works...So i'll try to read the file from that regex to end..so..

if [[ "$line" =~ /regex/,$p ]];

And nothing! ...

I can do a:

myFile.txt | sed -n '/regex/,$p'

wow..

Offline

#5 2008-12-04 07:11:26

oxoxo
Member
Registered: 2008-10-31
Posts: 66

Re: Complex Control Statements

:mad:ok supply the script with an existing file.

#!/bin/bash

FILE="$1"

echo "You Entered $FILE"

if [ -f $FILE ]; then
   tmp=$(cat $FILE)


   MyVar=$(echo $tmp | sed -n '/regex/,/regex/{/regularx/d;p\}' |\
       sed -n '/---/,+3!p' | sed -n '/#/!p' | sed 's/^[ ]*//' |\
       sed -e s/[^:]*://)
   echo "$MyVar"
fi

save the contents of that file in a tmp varaible. echo tmp and change the file with sed and store that into a myVar varaible. Echo myVar varaible..
why isnt that working?

wow..
So i try one by one..and stilll nothing...

# $tmp has the contents of the file
# This is all outside of: if [ -f $FILE ]; then tmp=(cat $FILE)
wow=$(echo $tmp | sed -n '/regex/,/regex/{/regex/d;p}')
wow2=$(echo $wow | sed -n '/---/,+3!p' )
wow3=$(echo $wow2 | sed -n '/#/!p' )
wow4=$(echo $wow3 | sed 's/^[ ]*//' )
wow5=$(echo $wow4 | sed -e s/[^:]*:// )

echo "$wow5"

Last edited by oxoxo (2008-12-04 08:15:44)

Offline

Board footer

Powered by FluxBB