Need little help with a awk script 
Author Message
 Need little help with a awk script

Hi,

im searching for a solution for the following problem:

i need a script, that prints out a word, that is between two specific words.
that all is in one line. this line contains several other characters. can i
use two seperators or anything like that?
any other solution (for linux) with sed or something like that would help
too.

example:

tue 11:11:01 anything specword anything specword anything
or
tue 11:11:01 anything specword anything any thing specword anything

thanks for help !

cu



Thu, 24 Jun 2004 06:57:36 GMT  
 Need little help with a awk script

Quote:

> Hi,

> im searching for a solution for the following problem:

> i need a script, that prints out a word, that is between two specific words.
> that all is in one line. this line contains several other characters. can i
> use two seperators or anything like that?
> any other solution (for linux) with sed or something like that would help
> too.

> example:

> tue 11:11:01 anything specword anything specword anything
> or
> tue 11:11:01 anything specword anything any thing specword anything

Wasn't fully clear what you actually wanted to do here.  Print the
`anything' that occurs betwee specword instances but then in your
second line there are two words between the specwords, and your
presentation says you want `a' word (i.e. single).

Maybe you can give a better example of exactly what you want?

Maybe this is all you need:

   gawk -F"specword" '{print $2}'

Using `specword' as FS (Field Separator):
Should print only material between occurances of specword in your
example data.  This assumes specword is constant and only appears
twice per line.



Thu, 24 Jun 2004 09:03:23 GMT  
 Need little help with a awk script
Ok,

yes i mean, that the characters between specword may be separated by a blank
too.
so i cant get them with $X. if i use specword as FS i get the rest of the
line after specword.

specword is always twice per line and always the same. youre right, i dont
want to print out only one word. i want to
print out all between specword and the second specword.



Quote:

> > Hi,

> > im searching for a solution for the following problem:

> > i need a script, that prints out a word, that is between two specific
words.
> > that all is in one line. this line contains several other characters.
can i
> > use two seperators or anything like that?
> > any other solution (for linux) with sed or something like that would
help
> > too.

> > example:

> > tue 11:11:01 anything specword anything specword anything
> > or
> > tue 11:11:01 anything specword anything any thing specword anything

> Wasn't fully clear what you actually wanted to do here.  Print the
> `anything' that occurs betwee specword instances but then in your
> second line there are two words between the specwords, and your
> presentation says you want `a' word (i.e. single).

> Maybe you can give a better example of exactly what you want?

> Maybe this is all you need:

>    gawk -F"specword" '{print $2}'

> Using `specword' as FS (Field Separator):
> Should print only material between occurances of specword in your
> example data.  This assumes specword is constant and only appears
> twice per line.



Thu, 24 Jun 2004 19:22:41 GMT  
 Need little help with a awk script

Quote:

> specword is always twice per line and always the same. youre right, i dont
> want to print out only one word. i want to
> print out all between specword and the second specword.

Try this:

#------ Example #1 ----------------------------------------------
#       find numbers of first and last field to be printed
#       then print from first to last field
{
        sep = "SomeSeparator"
        for ( n = i = 1; n<=NF; n++ )
                if ( $n == sep ) I[i++] = n
        if ( i < 3 )
                print
        else
        {
                for ( n = I[1]+1; n < I[2]; n++ )
                        printf("%s ", $n )
                print ""
        }

Quote:
}

#------ Example #2 ----------------------------------------------
#       delete - skip - delete
#       then print line
{
        sep = "SomeSeparator"
        for ( n = 1;    n <= NF && $n != sep; n++ )  $n = ""
        for ( $n = "" ; n <= NF && $n != sep; n++ )        ;
        for ( ;         n <= NF;              n++ )  $n = ""
        print

Quote:
}

#----------------------------------------------------------------


Fri, 25 Jun 2004 22:29:56 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Need help with awk script

2. need help on awk script

3. Need help to write a simple awk script

4. Need help with simple awk script

5. Little help with PPPMain script in Oberon.Text?

6. A little script to help resolve dependencies on installed packages (RPM,Linux,Python)

7. Help optimising AWK script

8. Help with A simple awk script.

9. Script Help with awk

10. help for newbie: way to get the value of an awk variable in a shell script

11. Help with awk script

12. awk script help

 

 
Powered by phpBB® Forum Software