![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 |
|
||||
|
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 |
|
||||
|
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? |
|
||||
|
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.. |
|
||||
|
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
Last edited by era; 04-23-2008 at 01:16 PM.. Reason: Simplify sed script further; reset c1 = c2 = "" at end |
|
||||
|
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 |
![]() |
| Bookmarks |
| Tags |
| perl, perl regex, regex, solaris |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|