Unix/Linux
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   Web Development Archives FAQs Unix/Linux

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Web Development Archives Sponsor:
  #1  
Old July 2nd, 2008, 09:30 AM
Injam
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Please help me in writing script

Hi ,
I have the following two files.The characters 14-18 in file input2
will match 2nd field deleimited by ~ in file input1.

swadmin@tb142:/rangedoms1/working/
cat input1
P00000012~00027
P00000027~00061
P00000270~00417
P00000271~00418
P00000272~00419
P00000273~00420
P00000274~00422
P00000275~00424
P00000276~00428
P00000277~00429
P00000278~00431
P00000279~00432
P00000329~00483
P60000329~00483
P50000329~00483
P40000329~00483
P30000329~00483
P20000329~00483
P10000329~00483
P00000483~00639
P01000079~00178
P11000079~00178
P90000079~00178
P80000079~00178
P70000079~00178
P60000079~00178
P50000079~00178
P40000079~00178
P30000079~00178
P20000079~00178
P10000079~00178
P00000178~00306
swadmin@tb142:/rangedoms1/working/
cat input2






Now I want the file that contains every line in input2 but the
characters 14-18 must be replaced with the matching field1 delimited
by ~ in file input1 and it should not be repeated.
I have used the following script which displays
swadmin@tb142:/rangedoms1/working/
>awk -F'~' 'NR==FNR{a[$2]=

$1;next}{print substr($0,1,13),a[substr($0,14,5)],substr($0,19)}'
input1 input2
0001349000174 P00000012
0001349000174 P10000329
0001349000174 P10000079
0001349000174 P10000079
0001349000174 P10000329
0001349000174 P10000079

But P10000079, P10000329 are repeated which we don’t want.

resulting file should look like the following

0001349000174
0001349000174
0001349000174
0001349000174
0001349000174
0001349000174
I have used the following script which displays
swadmin@tb142:/rangedoms1/working/
>awk -F'~' 'NR==FNR{a[$2]=

$1;next}{print substr($0,1,13),a[substr($0,14,5)],substr($0,19)}'
input1 input2
0001349000174 P00000012
0001349000174 P10000329
0001349000174 P10000079
0001349000174 P10000079
0001349000174 P10000329
0001349000174 P10000079

But P10000079, P10000329 are repeated which we don’t want.

Many thanks in advance for help being done.

Regards
Injam

Reply With Quote
Reply

Viewing: Web Development Archives FAQs Unix/Linux > Please help me in writing script


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

vB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT