gawk and gensub


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting gawk and gensub
# 1  
Old 05-10-2008
gawk and gensub

Hi,

Code:
$ echo "Hellooo" | gawk '{print gensub(/o{3}/, "z", 1)}'

doesn't return "Hellz" as expected while:
Code:
$ echo "Hellooo" | awk '{print gensub(/o+/, "z", 1)}'

produces "Hellz" correctly. Are the {m,n} quantifiers not supported in gensub?

I know that sub or gsub could do the job. It's just an example. I need gensub for the possibility it offers to use back references.

gawk 3.1.5
# 2  
Old 05-10-2008
Use −−re−interval to enable this feature in gawk:

Code:
echo "Hellooo" | gawk --re-interval '{print gensub(/o{3}/, "z", 1)}'

Regards
# 3  
Old 05-10-2008
Thank you Franklin52. Works like a charm. (should have read the man thoroughtly ).
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Awk: split and gensub query

Hi All, Thanks for answering my previous question. Could you please explain the highlighted code? awk -v pos='9 27 39 54 59 64 71 78 83 103 108' 'BEGIN{split(pos,var)} {for (i in var) $0=gensub(/./,"|",var)} 1' test.txt | head I understood that the split function splits the pos string into... (2 Replies)
Discussion started by: mrcool4
2 Replies

2. SCO

Need help with gawk

I am trying to use gawk to search a file and put the second value of the string into a string. gawk -F: '$1~/CXFR/ {print $2}' go.dat Below is the file 'go.dat' ==================== HOME :/ CTMP :/tmp CUTL :/u/rdiiulio/bin CWRK :/u/work CXFR :/u/xfer ... (1 Reply)
Discussion started by: trolley
1 Replies

3. Shell Programming and Scripting

Gawk gensub, match capital words and lowercase words

Hi I have strings like these : Vengeance mitt Men Vengeance gloves Women Quatro Windstopper Etip gloves Quatro Windstopper Etip gloves Girls Thermobite hooded jacket Thermobite Triclimate snow jacket Boys Thermobite Triclimate snow jacket and I would like to get the lower case words at... (2 Replies)
Discussion started by: louisJ
2 Replies

4. UNIX for Dummies Questions & Answers

gensub and arraywith awk

Hi Unix.com ! I would need some help for something I don't understand :confused: input: 111|2 Y Z blue. 333|4 W X blue.; 5 Y Z red. 666|7 W X red.; 8 Y Z blue. 999|10 U V red.; 11 W X blue.; 12 Y Z red. From $2, I would like to remove the sub-strings containing "blue" (and the... (4 Replies)
Discussion started by: beca123456
4 Replies

5. Programming

need help with gawk script

hi i've already created this script. When I execute the script it takes the argument and compares it to the 3rd column of the script. What I was wondering if I could get some help with is. I want to add another column to the script and it will be the result of a set number for example, (2000 - 3rd... (3 Replies)
Discussion started by: gengar
3 Replies

6. Shell Programming and Scripting

Gawk filter

People, Ive been trying to make a script but i just cant figure it out. Problem/ Case: I have a logfile.txt that contains data. The only two things i need to filter on = $1 (date), $6 (errorcode). In the script i am trying to make, u need to fill in a date. So he searches on that date... (11 Replies)
Discussion started by: Pow3R
11 Replies

7. Shell Programming and Scripting

Gawk Help

Hi, I am using the script to print the portion of the file containing a particular string. But it is giving error "For Reading (No such file or directory). I am using cygwin as unix simulator. cat TT35*.log | gawk -v search="12345678" ' /mSOriginating /,/disconnectingParty/ { ... (1 Reply)
Discussion started by: vanand420
1 Replies

8. Shell Programming and Scripting

gawk to perl

Hi all I’m looking for a perl equivalent to this command string I need to imbed this in a existing perl script cat file1 | gawk -F"|" '{print $1","$2,",",$3,",",$11 >> "new-file"}' Thank you (4 Replies)
Discussion started by: Ex-Capsa
4 Replies

9. Shell Programming and Scripting

gawk and bash

Hi. I'm having trouble using gawk within a bash script and I can't figure out why. I have a command that takes in a data file with two columns, the first one numbers and the second words. My code takes each line, and prints the word its corresponding number of times. The code works from the... (2 Replies)
Discussion started by: cdislater
2 Replies

10. Shell Programming and Scripting

gawk HELP

I have to compare records in two files. It can be done using gawk/awk but i am unable to do it. Please help me File1 ABAAAAAB BC asa sa ABAAABAA BC bsa sm ABBBBAAA BC bxz sa ABAAABAB BC csa sa ABAAAAAA BC dsa sm ABBBBAAB BC dxz sa File 2 ABAAAAAB BC aas ba ABAAAAAB BC asa sa... (6 Replies)
Discussion started by: sandeep_hi
6 Replies
Login or Register to Ask a Question