The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Script for Country Codes zanetti321 UNIX for Advanced & Expert Users 19 04-04-2008 12:09 PM
How the first script should notify in case there is no response from second rajusa10 Shell Programming and Scripting 4 03-19-2008 01:35 PM
Faster then cp ? yoavbe Shell Programming and Scripting 6 07-10-2006 02:14 PM
faster way to loop? tads98 UNIX for Advanced & Expert Users 9 05-10-2006 04:07 PM

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

Join Date: Feb 2008
Posts: 39
Country Codes script faster response ;please help

Dear all

I have group of input lines which look like this


These input lines is placed in a file named phonelines.txt and there is a script which match $4 and $5 with country codes placed in another file named country-codes.txt and its contents is :

Italy 39
Libyana 21892
Thuraya Satellite 88216
Lebanon 964
England 44

and so on this file will be containning country codes of alot of countries

I have a script which work on these files and the output look like this

Belgium1 ISC 3 924556808 393475157928 b 1B Libyana Italy
Italy ISC 151 925082838 447717254923 b 26 Libyana England
ISC BT-GlasGow 152 88216900500 218925288836 f 1B Thuraya Libyana
ISC Spain-Telefonica 14 964188208970 218925735325 b 29 Lebanon Libyana

as shown there are two added fields according to the country codes

The problem that the script i am using is slow because i have large input lines (may reach 300000) and i have lot of countries so i want a faster code

The code i have is:
sed 's=\(.*\) \(.*\)=awk :{if($4~/^\2/)print $0" \1";else print}: phonelines.txt=' country-codes.txt|tr ':' "'"|sh|awk 'NF==8{print}' >newlines.txt
sed 's=\(.*\) \(.*\)=awk :{if($5~/^\2/)print $0" \1";else print}: newlines.txt=' country-codes.txt|tr ':' "'"|sh|awk 'NF==9{print}'

So do you have faster one to be more reliable ?

Note : I am using Solaris 8 SUN280R

Please advise
Zanetti
  #2 (permalink)  
Old 04-23-2008
zanetti321 zanetti321 is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 39
Sorry

Sorry but i forget to put the input lines which is mentioned in my first words; it look like this:

Belgium1 ISC 3 924556808 393475157928 b 1B
Italy ISC 151 925082838 447717254923 b 26
ISC BT-GlasGow 152 88216900500 218925288836 f 1B
ISC Spain-Telefonica 14 964188208970 218925735325 b 29

Thanks
Zanetti
  #3 (permalink)  
Old 04-23-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
The perl script I wrote three weeks ago might be faster than what you ended up with; have you tested?

Script for Country Codes

Do you have some sort of timing data, what's the current performance and what would you like for it to be?
  #4 (permalink)  
Old 04-23-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Ugh, looking closer at that code, I can see that it's going to be slow. It starts a separate awk for each telephone code! Please test the Perl script on some real-world data; if it feels fast enough, we can work on making it format the output the way you want it.

(Certainly the awk code would be possible to optimize, at least to make it a bit less hungry for processes; but if your awk is old and tired, Perl is probably easier to work with. At least it won't throw syntax errors if we don't have exactly the same version.)

Last edited by era; 04-23-2008 at 01:11 PM..
  #5 (permalink)  
Old 04-23-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Actually, this any better?

Code:
vnix$ sed -e 's%\(.*\) \(.*\)%$4 ~ /^\2/ { c1=" \1" } $5 ~ /^\2/ { c2=" \1" }%' \
>   -e '$a\{ print $0 c1 c2; c1 = c2 = ""; }' country-codes.txt |
> awk -f - phonelines.txt
Belgium1 ISC 3 924556808 393475157928 b 1B Italy
Italy ISC 151 925082838 447717254923 b 26 England
ISC BT-GlasGow 152 88216900500 218925288836 f 1B Thuraya Satellite Libyana
ISC Spain-Telefonica 14 964188208970 218925735325 b 29 Lebanon Libyana
The output is ambiguous when you have one code but not the other, is that a problem?

Last edited by era; 04-23-2008 at 01:16 PM.. Reason: Simplify sed script further; reset c1 = c2 = "" at end
  #6 (permalink)  
Old 04-23-2008
zanetti321 zanetti321 is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 39
Reply

Dear Era

The problem is that the perl script dont output my need at all ; i prefer to use the last code which is :

vnix$ sed -e 's%\(.*\) \(.*\)%$4 ~ /^\2/ { c1=" \1" } $5 ~ /^\2/ { c2=" \1" }%' \
> -e '$a\{ print $0 c1 c2; c1 = c2 = ""; }' country-codes.txt |
> awk -f - phonelines.txt

Do you mean that these lines will be wrote in a seperate then change to excutable and run it or run it manually from the command line

Is this seems faster; also does it in need any modifications?

Zanetti
Closed Thread

Bookmarks

Tags
perl, perl regex, regex, solaris

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 04:09 AM.


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