"awk '/[0-9]{4}/' file" not works, why ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting "awk '/[0-9]{4}/' file" not works, why ?
# 1  
Old 08-26-2011
"awk '/[0-9]{4}/' file" not works, why ?

Hello, my question comes with the following code:
Code:
[river@localhost CLI010001]$ cat  fan_get.txt 
Source                                          Speed              Status              Mode
-------------------------------------------------------------------------------------------------------
PS A,Virtual Fan Group #1                       3600 RPM           Normal              Internal
PS A,Virtual Fan Group #1,Fan #1                2700 RPM           Normal
PS A,Virtual Fan Group #1,Fan #2                4300 RPM           Normal
PS A,Virtual Fan Group #1,Fan #3                3000 RPM           Normal
PS A,Virtual Fan Group #1,Fan #4                4300 RPM           Normal
PS A,Virtual Fan Group #1,Fan #5                3000 RPM           Normal
PS A,Virtual Fan Group #1,Fan #6                4700 RPM           Normal
PS A,Virtual Fan Group #1,Fan #7                2800 RPM           Normal
PS A,Virtual Fan Group #1,Fan #8                4400 RPM           Normal
PS B,Virtual Fan Group #2                       3500 RPM           Normal              Internal
PS B,Virtual Fan Group #2,Fan #1                2500 RPM           Normal
PS B,Virtual Fan Group #2,Fan #2                4000 RPM           Normal
PS B,Virtual Fan Group #2,Fan #3                2500 RPM           Normal
PS B,Virtual Fan Group #2,Fan #4                4300 RPM           Normal
PS B,Virtual Fan Group #2,Fan #5                2800 RPM           Normal
PS B,Virtual Fan Group #2,Fan #6                4500 RPM           Normal
PS B,Virtual Fan Group #2,Fan #7                3100 RPM           Normal
PS B,Virtual Fan Group #2,Fan #8                4400 RPM           Normal
-------------------------------------------------------------------------------------------------------

[river@localhost CLI010001]$ awk '/[0-9]{4}/' fan_get.txt 
[river@localhost CLI010001]$

Why I get no output after execute "awk '/[0-9]{4}/' fan_get.txt " ? I think many lines match it, e.g. 4400, 3100 ... ,
Thanks!
# 2  
Old 08-26-2011
Try:
Code:
awk '/[0-9]\{4\}/' fan_get.txt

PS: This is a long story about interval expressions support in awk. If this won't work then it means your awk doesn't support it.
# 3  
Old 08-26-2011
Its equivalent of the below grep

Code:
 
grep "[0-9]\{4\}" file

# 4  
Old 08-26-2011
Code:
[river@localhost CLI010001]$ awk '/[0-9]\{4\}/' fan_get.txt
[river@localhost CLI010001]$

sorry, it does not work. Does it means that awk does not support all the regular expression rules ?
# 5  
Old 08-26-2011
If you are using gawk, turn on re-interval option. --re-interval. Otherwise, go through the long way
Code:
awk '/[0-9][0-9][0-9][0-9]/' file

# 6  
Old 08-26-2011
Some AWKs' regular expression flavor may not support interval expressions (in your example, the {4} part), even though the standard has stated (for at least 15 years) that AWK's regular expression support is the extended regular expression flavor (which includes interval expression support) plus some minor escape sequence extensions.

In particular, I remember, years ago, bumping into this when testing scripts on GNU AWK. Without the --re-interval option, the feature would not be enabled.

Perhaps your AWK lacks support for it? Which implementation are you using?

Regards,
Alister
This User Gave Thanks to alister For This Post:
# 7  
Old 08-26-2011
Thanks, I should add "--posix" or "--re-interval".
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

3. Shell Programming and Scripting

how to use "cut" or "awk" or "sed" to remove a string

logs: "/home/abc/public_html/index.php" "/home/abc/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" how to use "cut" or "awk" or "sed" to get the following result: abc abc xyz xyz xyz (8 Replies)
Discussion started by: timmywong
8 Replies

4. Red Hat

files having Script which works behind "who" & "w" commands

Dear All, plz print the path of files which have the script of "who" & "w" commands. thnx in advance. (6 Replies)
Discussion started by: saqlain.bashir
6 Replies

5. UNIX for Dummies Questions & Answers

script works well but displays " line 6: =: No such file or directory"

strange :) can you tell why?:cool: #!/bin/bash echo " enter your age " read age if ; then echo " you do not have to pay tax " elif ]; then echo " you are eligible for income tax " else echo " you dont have to pay tax " fi (3 Replies)
Discussion started by: me.
3 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. Shell Programming and Scripting

Help to change the file with "sed" and "awk"

Hi experts I want your help to change the file format to my wanted version, please give me a hand thanks $cat file install pass make os pass make build kernel failed usb storage pass chane to | *install* | *make os* | *make build kernel* | *usb storage* | | pass | pass... (7 Replies)
Discussion started by: yanglei_fage
7 Replies

8. Shell Programming and Scripting

cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g'

hi All, cat file_name | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' Can this be done by using sed or awk alone (4 Replies)
Discussion started by: harshakusam
4 Replies

9. Shell Programming and Scripting

help for saving vertical datas to horizontal with "awk" or "cut"

hi, i have a file having datas like that ./a.txt 12344 12345 12346 12347 ..... ..... ... i want to save this datas to another file like that ./b.txt 12344 12345 12346 12347 ... ... ... i think awk can make this but how? :) waiting for ur help. (3 Replies)
Discussion started by: mercury
3 Replies

10. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies
Login or Register to Ask a Question