The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-19-2008
jolecanard jolecanard is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 36
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
  #2 (permalink)  
Old 11-19-2008
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,440
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..
  #3 (permalink)  
Old 11-19-2008
jolecanard jolecanard is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 36
Thank you!
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:22 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0