![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| gawk script | zoo591 | Shell Programming and Scripting | 2 | 05-28-2008 08:42 PM |
| awk,gawk in bat file | andrej | Shell Programming and Scripting | 0 | 05-09-2008 09:45 AM |
| gawk HELP | sandeep_hi | Shell Programming and Scripting | 6 | 06-19-2006 09:56 AM |
| starting gawk from env | odys | Shell Programming and Scripting | 6 | 02-16-2005 02:25 PM |
| rs and ors in gawk ...???? | moxxx68 | Shell Programming and Scripting | 2 | 10-05-2004 01:52 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Substitution using awk/gawk
Hello, I have a file containing lines such as: Code:
(1 104 (16) (17) (18) (102))$
(1 105 (16) (17) (19:21) (102))$
I would like to extract the numbers, only by using awk (or gawk). I do not want to use "sed" as it is very slow. For now my solution consists in using the sub command with gawk, and substitute "(", ")" and "$" by "". However I don't know how to do these substitution with only one "sub" command (I am using 4 "sub" commands). Do you have any idea how I could improve my script to do that? Thanks |
|
||||
|
tr was made for that. Code:
tr -d '($)' < file And here is the time test: Code:
# time awk '{gsub("[($)]","",$0)}1' file > /dev/null
real 0m0.311s
user 0m0.244s
sys 0m0.028s
# time tr -d '($)' < file > /dev/null
real 0m0.065s
user 0m0.024s
sys 0m0.004s
# time sed 's/(\|\$\|)//g' file > /dev/null
real 0m1.144s
user 0m1.092s
sys 0m0.000s
# wc file
18000 108000 738000 file
Last edited by danmero; 11-19-2008 at 09:17 PM.. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|