![]() |
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 |
| modify a particular pattern starting from second line of the search pattern | imas | UNIX for Dummies Questions & Answers | 1 | 10-12-2008 01:19 PM |
| modify a particular pattern starting from second line of the search pattern | imas | UNIX for Dummies Questions & Answers | 2 | 10-12-2008 11:30 AM |
| How can you delete records in a file matching a pattern? | mode09 | UNIX for Dummies Questions & Answers | 2 | 07-15-2008 01:53 PM |
| exclude columns with a matching line pattern | greptastic | UNIX for Dummies Questions & Answers | 5 | 06-30-2008 03:32 AM |
| Multile Pattern Search in a same line and delete | sasree76 | Shell Programming and Scripting | 2 | 04-16-2008 02:12 PM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
comment/delete a particular pattern starting from second line of the matching pattern
Hi,
I have file 1.txt with following entries as shown: 0152364|134444|10.20.30.40|015236433 0233654|122555|10.20.30.50|023365433 ** ** ** In file 2.txt I have the following entries as shown: 0152364|134444|10.20.30.40|015236433 0233654|122555|10.20.30.50|023365433 0789456|332211|10.20.30.40|078945633 1234567|225522|10.20.30.50|123456733 0321654|999999|10.20.30.40|032165433 0456123|777899|10.20.30.40|045612333 *** *** *** I want take the IP Address column from 1.txt and then search it in 2.txt and comment the duplicate entry from second matched pattern. i.e., i need to have the following output in 2.txt as shown: 0152364|134444|10.20.30.40|015236433 0233654|122555|10.20.30.50|023365433 #0789456|332211|10.20.30.40|078945633 #1234567|225522|10.20.30.50|123456733 #0321654|999999|10.20.30.40|032165433 #0456123|777899|10.20.30.40|045612333 *** *** *** Below is the script i wrote but it will comment all the duplicate entries: for i in `cat 1.txt |cut -d"|" -f3` do cat 2.txt |sed "s/^\(.*\|$i\|.*)/#/g" > tmp.txt mv tmp.txt 2.txt done Can some one guide me how to leave the first duplicate entry untouched and comment/delete from second duplicate entry and so on. ![]() Please do not close this thread if you do not know the answer. Thanks -Imas |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|