![]() |
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 |
| 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 |
| Shell Script Unique Identifier Question | grahambo2005 | UNIX for Dummies Questions & Answers | 7 | 07-22-2008 12:41 PM |
| how can i replace / with new line in shell script or sed ? | mail2sant | Shell Programming and Scripting | 3 | 04-25-2008 01:59 AM |
| Problem with shell script...ORA-00904:invalid identifier | bhagat.singh-j | Shell Programming and Scripting | 12 | 11-13-2006 10:33 AM |
| find a shell and replace the line | jvellon | UNIX for Advanced & Expert Users | 1 | 06-13-2006 09:44 PM |
| how to replace a line in a file using shell script | cs_sakthi | UNIX for Advanced & Expert Users | 3 | 01-27-2002 11:57 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
shell script to find and replace a line using a identifier
Hi all
im having trouble starting with a shell script, i hope someone here can help me i have 2 files file1: 404905.jpg 516167 404906.jpg 516168 404917.psd 516183 404947.pdf 516250 file2: 516250 /tmp/RecyclePoster18241.pdf 516167 /tmp/ReunionCardFINAL.jpg 516168 /tmp/MPP-3013594-05012009/ReunionBack.jpg 516183 /tmp/Stamp8x5.psd my output woulbe like: ouput: 516250 516250 /tmp/RecyclePoster18241.pdf 516167 404905.jpg /tmp/ReunionCardFINAL.jpg 516168 404906.jpg /tmp/MPP-3013594-05012009/ReunionBack.jpg 516183 404917.psd /tmp/Stamp8x5.psd note that file1 and file2 is not in particular order it could be 516183 404917.psd 404947.pdf 516250 and so on... although numbers 516183 and 404947 are unique which can be use as an identifier for the output thanks in advance Last edited by kenray; 05-06-2009 at 09:42 AM.. |
|
||||
|
hi thanks for the reply,
example in line 1 of file1 which is: 404905.jpg 516167 i need to replace 404905.jpg with /tmp/ReunionCardFINAL.jpg using file2 line which would result in 516167 /tmp/ReunionCardFINAL.jpg although lines may not be in order, im not sure if while read statement can do job but anything similar to the output is fine |
|
||||
|
ahh yes, sorry for that
file1: 404905.jpg 516167 404906.jpg 516168 404917.psd 516183 404947.pdf 516250 file2: 516250 /tmp/RecyclePoster18241.pdf 516167 /tmp/ReunionCardFINAL.jpg 516168 /tmp/MPP-3013594-05012009/ReunionBack.jpg 516183 /tmp/Stamp8x5.psd ouput: 516250 404947.pdf /tmp/RecyclePoster18241.pdf 516167 404905.jpg /tmp/ReunionCardFINAL.jpg 516168 404906.jpg /tmp/MPP-3013594-05012009/ReunionBack.jpg 516183 404917.psd /tmp/Stamp8x5.psd |
|
||||
|
if you have Python can able to use it, here's an alternative solution
Code:
#!/usr/bin/env python
d={}
for line in open("file1"):
line= line.strip().split()
d[line[-1]]=line[0]
for line in open("file2"):
line= line.strip().split()
print line[0],d[line[0]],''.join(line[1:])
Code:
# ./test.py 516250 404947.pdf /tmp/RecyclePoster18241.pdf 516167 404905.jpg /tmp/ReunionCardFINAL.jpg 516168 404906.jpg /tmp/MPP-3013594-05012009/ReunionBack.jpg 516183 404917.psd /tmp/Stamp8x5.psd |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|