Matched by /\B/ in GNU awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Matched by /\B/ in GNU awk
# 1  
Old 01-03-2010
Matched by /\B/ in GNU awk

My GNU awk's version is 3.1.5, the special regexp operator '\B' can't work as expected.
The document from "The GNU Awk User's Guide"
Quote:
\B
Matches the empty string that occurs between two word-constituent characters. For example, /\Brat\B/ matches ‘crate' but it does not match ‘dirty rat'. ‘\B' is essentially the opposite of ‘\y'.
It's my data file:
Code:
ABCDE
ABCD
ABC
AB
A

replaces all /\B/ with gsub:
Code:
$ awk '{gsub(/\B/,"X")}1' data 
AXBXCXDE
AXBXCD
AXBC
AXB
A

And, the expected result is:
Code:
$ awk '{gsub(/\B/,"X")}1' data 
AXBXCXDXE
AXBXCXD
AXBXC
AXB
A


Last edited by redraiment; 01-04-2010 at 07:22 AM..
# 2  
Old 01-04-2010
This behavior seams to be version specific:

Code:
$ awk --version|head -1
GNU Awk 3.1.5
$ awk 'gsub(/\B/,"X")||1'  data
AXBXCXDE
AXBXCD
AXBC
AXB
A

Code:
% awk --version | head -1
GNU Awk 3.1.7
% awk 'gsub(/\B/,"X")||1'  data
AXBXCXDXE
AXBXCXD
AXBXC
AXB
A

# 3  
Old 01-04-2010
Quote:
Originally Posted by radoulov
This behavior seams to be version specific:

Code:
$ awk --version|head -1
GNU Awk 3.1.5
$ awk 'gsub(/\B/,"X")||1'  data
AXBXCXDE
AXBXCD
AXBC
AXB
A

Code:
% awk --version | head -1
GNU Awk 3.1.7
% awk 'gsub(/\B/,"X")||1'  data
AXBXCXDXE
AXBXCXD
AXBXC
AXB
A

Thank you very much! This bug has been fixed in v3.1.6Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to delete content before and after a matched pattern

Hello, I have been trying to write a script where I could get awk to delete data before and after a matched pattern. For eg Raw data Start NAME = John Age = 35 Occupation = Programmer City = New York Certification Completed = No Salary = 80000 End Start NAME = Mary Age = 25... (2 Replies)
Discussion started by: sidnow
2 Replies

2. Shell Programming and Scripting

Replacing matched patterns in multiple files with awk

Hello all, I have since given up trying to figure this out and used sed instead, but I am trying to understand awk and was wondering how someone might do this in awk. I am trying to match on the first field of a specific file with the first field on multiple files, and append the second field... (2 Replies)
Discussion started by: karlmalowned
2 Replies

3. Shell Programming and Scripting

Number of matches and matched pattern(s) in awk

input: !@#$%2QW5QWERTAB$%^&* The string above is not separated (or FS=""). For clarity sake one could re-write the string by including a "|" as FS as follow: !|@|#|$|%|2QW|5QWERT|A|B|$|%|^|&|* Here, I am only interested in patterns (their numbers are variable between records) containing... (16 Replies)
Discussion started by: beca123456
16 Replies

4. Shell Programming and Scripting

awk - how to print specific field if a string is matched

hi gurus, I would like to be able to use awk to process 1 file as such: abc 1 2 3 4 5 6 7 8 9 10 flags 1 2 4 flags 1 2 5 abc 2 3 4 5 6 7 8 9 10 11 flags 1 2 3 abc 4 5 6 7 8 9 6 7 78 89 flags 1 2 3 flags 1 2 4 flags 1 2 3 4 I would like to be able to print field 1 and 5 when the... (4 Replies)
Discussion started by: revaroo
4 Replies

5. Shell Programming and Scripting

awk - Print whole string ending with a Tab if key matched

Hi , I am looking to print the whole string from file2.txt but it is only printing 77 but not the whole matched string from File2.txt Any help is appreciated. Thanks, Script awk ' BEGIN { OFS="\t" out = "a.txt"} NR==FNR && NF {a=$0; next} function print_65_11() { if... (11 Replies)
Discussion started by: High-T
11 Replies

6. Shell Programming and Scripting

sed , awk script for printing matched line before regular expression

hi All , I am having a large file with lots of modules as shown below ############################################### module KKK kksd kskks jsn;lsm jsnlsn; Ring jjsjsj kskmsm jjs endmodule module llll 1kksd11 k232skks j33sn;l55sm (6 Replies)
Discussion started by: kshitij
6 Replies

7. Shell Programming and Scripting

print the whole row in awk based on matched pattern

Hi, I need some help on how to print the whole data for unmatched pattern. i have 2 different files that need to be checked and print out the unmatched patterns into a new file. My sample data as follows:- File1.txt Id Num Activity Class Type 309 1.1 ... (5 Replies)
Discussion started by: redse171
5 Replies

8. Shell Programming and Scripting

Use AWK to move matched line back one?

Can somebody help me with this? I'm sure it's a no-brainer if you know awk... but I don't. Input: Blah Blah Me love you long time Blah Blah awk magic with 'long time' ==> Output: Blah Blah Me love you long time (0 Replies)
Discussion started by: Ryan.
0 Replies

9. Shell Programming and Scripting

AWK Print Line If Specific Character Is Matched

Hello, I have a file as such: FFFFFFF6C000000 225280 225240 - - rwxs- FFFFFFFF79C00000 3240 3240 - - rwxs- FFFFFFFF7A000000 4096 4096 - - rwxs- FFFFFFFF7A400000 64 64 ... (3 Replies)
Discussion started by: PointyWombat
3 Replies

10. Shell Programming and Scripting

AWK - Extracting matched line

Hi all, I have one more query related to AWK. I have the following csv data: ,qwertyA, field1, field2, field3, field4, field5, field6 ,,,,,,,,,,,,,,,,,,,100,200 ,,,,,,,,,,,,,,,,,,,300,400 ,qwertyB, field1, field2, field3, field4, field5, field6 ,,,,,,,,,,,,,,,,,,,100,200... (9 Replies)
Discussion started by: not4google
9 Replies
Login or Register to Ask a Question