grep help, how do i make this shorter?

2008-01-31 Thread UniXman1234

Hi everyone, im trying to make the following command line shorter by
introducing a script that join up all the grep commands

 ./new1a < numbers.txt | grep -i -v '^a ' | grep -i -v '^the ' | grep -i -v
'^or ' | sort -f

How would I go about merging all the greps into a scripe and putting all the
words that should be excluded into a data file

so would it be something like this

---exclude---

#!/bin/sh
# exclude.sh

grep -i -v ^datafile.txt
end--

---datafile.txt---
a
the
or
---end.txt---


so i would be able to execute it like

./new < numbers.txt | exclude | sort -f

Thank you, i tried doing every possible way i could think of but it doesnt
seem to work. Im a newb just started script programming 2 weeks ago

-- 
View this message in context: 
http://www.nabble.com/grep-help%2C-how-do-i-make-this-shorter--tp15198967p15198967.html
Sent from the Gnu - Bash mailing list archive at Nabble.com.





errexit does not exit script in subshells

2008-01-31 Thread Michael Potter
Bash Bunch,

Not surprisingly, bash does not exit the script when an error is detected in
a subshell.

I am hopeful that someone has a solution to this (other than: be careful to
not use subshells).

Here is the test run:
---
./subshellnofail.sh
BEGIN
ERROR: ./subshellnofail.sh 10 <- would like the script to stop here.
ONE
ERROR: ./subshellnofail.sh 10
---

Here is the sample script:
--
#!/bin/bash

set -o errexit
set -o noclobber
set -o nounset
set -o pipefail# if you fail on this line, get a newer version of bash.

function traperr
{
   echo "ERROR: ${BASH_SOURCE[0]} ${LINENO}"
   # exit 1   # does not seem to affect the program.
   # return 1 # does not seem to affect the program.
}

set -o errtrace
trap traperr ERR

echo "BEGIN"

cat /etc/passwd |while read aLine
do
   # in a subshell
   test=$(true | false | true |false);
done

echo "ONE"

while read aLine
do
   # not in a subshell
   test=$(true | false | true |false);
done 

Re: grep help, how do i make this shorter?

2008-01-31 Thread Bob Proulx
UniXman1234 wrote:
>  ./new1a < numbers.txt | grep -i -v '^a ' | grep -i -v '^the ' | grep -i -v
> '^or ' | sort -f
> 
> How would I go about merging all the greps into a scripe and putting all the
> words that should be excluded into a data file

Many different ways.  Look at the 'grep -f' option.  Look at using sed.

> so i would be able to execute it like
> 
> ./new < numbers.txt | exclude | sort -f

Here is one possibility.

  ./new < numbers.txt | grep -v -f exclude.txt | sort -f

HTH,
Bob




SOLUTION: errexit does not exit script in subshells

2008-01-31 Thread Michael Potter
Bash Bunch,

Here is how I 'solved' the problem:

function traperr
{
   echo "ERROR: ${BASH_SOURCE[0]} ${LINENO}"

   # if BASH_SUBSHELL is 0, then script will exit anyway.
   if (( $BASH_SUBSHELL >= 1 ))
   then
  kill $$
   fi
}

I put solved in quotes because I do not really care for this solution.
I hope someone will comment with a graceful solution.

--
Michael Potter

On Jan 31, 2008 11:43 AM, Michael Potter <[EMAIL PROTECTED]> wrote:

> Bash Bunch,
>
> Not surprisingly, bash does not exit the script when an error is detected
> in a subshell.
>
> I am hopeful that someone has a solution to this (other than: be careful
> to not use subshells).
>
> Here is the test run:
> ---
> ./subshellnofail.sh
> BEGIN
> ERROR: ./subshellnofail.sh 10 <- would like the script to stop here.
> ONE
> ERROR: ./subshellnofail.sh 10
> ---
>
> Here is the sample script:
> --
> #!/bin/bash
>
> set -o errexit
> set -o noclobber
> set -o nounset
> set -o pipefail# if you fail on this line, get a newer version of
> bash.
>
> function traperr
> {
>echo "ERROR: ${BASH_SOURCE[0]} ${LINENO}"
># exit 1   # does not seem to affect the program.
># return 1 # does not seem to affect the program.
> }
>
> set -o errtrace
> trap traperr ERR
>
> echo "BEGIN"
>
> cat /etc/passwd |while read aLine
> do
># in a subshell
>test=$(true | false | true |false);
> done
>
> echo "ONE"
>
> while read aLine
> do
># not in a subshell
>test=$(true | false | true |false);
> done 
> echo "TWO"
>
> test=$(true | false | true |false);
>
> echo "END"
>
> exit 0
> -
>
> echo $BASH_VERSION
> 3.2.17(1)-release
>
>