Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can awk use groups in regular expressions ?

Status
Not open for further replies.

majkinetor

Programmer
Feb 21, 2006
88
RS
I want to translate this line from SED to AWK:

s/(g1)(g2)/\1\n/g

is this possible to do in AWK ?
I didn't find anybody using \N in it.


If not,is there any variant of awk supporting this ?

thx.
 
Hi

Yes, [tt]gawk[/tt], the GNU version of [tt]awk[/tt]. But only in the [tt]gensub()[/tt] function.
Code:
[blue]master #[/blue]echo "hello world" | awk '{$0=gensub(/(^| )(.)/,"\\1[\\2]","g")}1'
[h]ello [w]orld

Feherke.
 
Its very strange though that program doesn't work at windows console ?!

I used this script:

Code:
{
      $0 = gensub(/(.+) (.+)/, "\\2 \\1", "g")
      print
}

When I create the file and use command

Code:
 echo | gawk -f script.awk

it works nice

but if I set the script in "..." it reports (not with this script:

gawk "{$0 = gensub(/(.+) (.+)/, "\\2 \\1", "g");print}" out

gawk: cmd. line:1: {$0 = gensub(/(.+) (.+)/, \\2
gawk: cmd. line:1: ^ backslash not last character on line
 
sorry, the above command is

Code:
echo abc def | gawk -f script.awk
 
Ah, stupid me....

... I work in 2 many languages...



Thank you :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top