regular expression grepping lines with VARIOUS number of blanks

Hi,

I need a regular expression grepping all lines starting with '*' followed by a VARIOUS number of blanks and then followed by the string 'Runjob=1'.

I tried that code, but it doesn't work:

 
grep -i '*'[ ]+'Runjob=1' INPUT_FILE >>OUTPUT_FILE 

Can someone help me?

Thanks

Hope this is what you are looking for.....
Try this:

grep '^*' ipfile | grep ' ' | grep 'string' >opfile

This can be done in one step using egrep. Read man pages of egrep for more details.
Please post sample i/p and expected o/p for best reply/solution.

No matter what kind of space or how many >1:

grep -E ^\*[[:space:]]\+Runjob=1 INPUT_FILE >>OUTPUT_FILE

thanks but both expressions didn't work :frowning:

echo "*        Runjob=1" |grep -E ^\*[[:space:]]\+Runjob=1
*        Runjob=1

For me it worked. Maybe post a excerpt of your input and use CODE tags when doing so.

zaxxon, I also don't get any output.

ABE2202, you can try this:

grep -e "\*[ ]+*.*Runjob=1" INPUT_FILE >> OUTPUT_FILE

Assuming that "a VARIOUS number of blanks" means "one or more blanks":

$
$ cat data.txt
first line
*Runjob=1
* Runjob=1
*  Runjob=1
*   Runjob=1
*    Runjob=1
*     Runjob=1
*      Runjob=1
*       Runjob=1
*        Runjob=1
*         Runjob=1
*          Runjob=1
*           Runjob=1
*            Runjob=1
last line
$
$ # using perl
$ perl -ne '/^*[ ]+Runjob=1/ and print' data.txt
* Runjob=1
*  Runjob=1
*   Runjob=1
*    Runjob=1
*     Runjob=1
*      Runjob=1
*       Runjob=1
*        Runjob=1
*         Runjob=1
*          Runjob=1
*           Runjob=1
*            Runjob=1
$
$ # using egrep
$ egrep '^*[ ]+Runjob=1' data.txt
* Runjob=1
*  Runjob=1
*   Runjob=1
*    Runjob=1
*     Runjob=1
*      Runjob=1
*       Runjob=1
*        Runjob=1
*         Runjob=1
*          Runjob=1
*           Runjob=1
*            Runjob=1
$
$ # using awk
$ awk '/^*[ ]+Runjob=1/' data.txt
* Runjob=1
*  Runjob=1
*   Runjob=1
*    Runjob=1
*     Runjob=1
*      Runjob=1
*       Runjob=1
*        Runjob=1
*         Runjob=1
*          Runjob=1
*           Runjob=1
*            Runjob=1
$
$

tyler_durden

@Franklin52
What I posted works on my GNU sed on my Debian box. For AIX I had to remove the backslash in front of the +.

echo "*        Runjob=1" |grep -E "^\*[[:space:]]+Runjob=1"

Which works on the GNU sed too I just saw. I think without backslash is correct anyway since it should be interpreted and not be protected.

Hi,

I am sorry to say, but it none of these commands work.
Maybe the reason is because I need it in bash-shell?!

For instance when I try following code

egrep '^*[ ]+Runjob=1' test.ini

or

egrep '*[ ]+Runjob=1' test.ini

I get the return message

*?+ not preceded by valid expression

Can someone help me?

---------- Post updated at 05:31 AM ---------- Previous update was at 05:28 AM ----------

following code worked:

 
grep -e "\*[ ]+*.*Runjob=1"

I'll try it right now, again thanks a lot to all of you :slight_smile: