Sponsored Content
Top Forums UNIX for Dummies Questions & Answers modify a particular pattern starting from second line of the search pattern Post 302246041 by imas on Sunday 12th of October 2008 12:30:28 PM
Old 10-12-2008
modify a particular pattern starting from second line of the search pattern

Hi,

I think you ppl did not get my question correctly, let me explain

I have 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 from second duplicate entry and so on.

Please do not close this thread if you do not know the answer.

Thanks
-Imas
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

modify a particular pattern starting from second line of the search pattern

Hi, I am new to this forum and i would like to get help in this issue. I have a file 1.txt as shown: apple banana orange apple grapes banana orange grapes orange .... Now i would like to search for pattern say apple or orange and then put a # at the beginning of the pattern... (2 Replies)
Discussion started by: imas
2 Replies

2. Shell Programming and Scripting

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... (4 Replies)
Discussion started by: imas
4 Replies

3. Shell Programming and Scripting

search a pattern and if pattern found insert new pattern at the begining

I am trying to do some thing like this .. In a file , if pattern found insert new pattern at the begining of the line containing the pattern. example: in a file I have this. gtrow0unit1/gctunit_crrownorth_stage5_outnet_feedthru_pin if i find feedthru_pin want to insert !! at the... (7 Replies)
Discussion started by: pitagi
7 Replies

4. Shell Programming and Scripting

How to use sed to modify a line above or below matching pattern?

I couldn't figure out how to use sed or any other shell to do the following. Can anyone help? Thanks. If seeing a string (e.g., TODAY) in the line, replace a string in the line above (e.g, replace "Raining" with "Sunny") and replace a string in the line below (e.g., replace "Reading" with... (7 Replies)
Discussion started by: sprinner
7 Replies

5. Shell Programming and Scripting

How to search pattern and add that pattern in next line

Hi All, I am new to shell scripting and need help in scripting using CSH. Here is what I am trying to so, 1. Search a specific string e.g. "task" from "task (input1, out1)". 2. Extract the arguements "input1" and "out1" 3. Add them in separate lines below. eg. "int input1" , " integer out1" ... (7 Replies)
Discussion started by: deshiashish
7 Replies

6. Shell Programming and Scripting

Search a pattern in a line and remove another pattern

Hi, I want to search a pattern in a text file and remove another pattern in that file. my text file look like this 0.000000 1.970000 F 303 - 1.970000 2.080000 VH VH + 2.080000 2.250000 VH VH + 2.250000 2.330000 VH L - 2.330000 2.360000 F H + 2.360000 2.410000 L VL - 2.410000 ... (6 Replies)
Discussion started by: sreejithalokkan
6 Replies

7. Shell Programming and Scripting

Remove duplicate line starting with a pattern

HI, I have the below input file /* ----------------- cmdsDlyStartFWJ -----------------*/ UNIX_JOB CMDS065J RUN ANY CMDNAME sleep 5 AGENT CMDSHP USER proddata RUN MON,TUE,WED,THU,FRI DELAYSUB 02:00 /* "Triggers daily file watcher jobs" */ ENVAR... (5 Replies)
Discussion started by: varun22486
5 Replies

8. UNIX for Dummies Questions & Answers

Grep -v lines starting with pattern 1 and not matching pattern 2

Hi all! Thanks for taking the time to view this! I want to grep out all lines of a file that starts with pattern 1 but also does not match with the second pattern. Example: Drink a soda Eat a banana Eat multiple bananas Drink an apple juice Eat an apple Eat multiple apples I... (8 Replies)
Discussion started by: demmel
8 Replies

9. Shell Programming and Scripting

Pattern search and modify the values

I have one file and the file may contain 500 to 15,000 records. I need to search pattern ^F509= and then increment the corresponding value by one and print the entire line. Please note that Its not a fixed length file. Can anyone please help? ex: ^F509=204656 ^F509=204656 ... (6 Replies)
Discussion started by: vinus
6 Replies

10. UNIX for Beginners Questions & Answers

Grep file starting from pattern matching line

I have a file with a list of references towards the end and want to apply a grep for some string. text .... @unnumbered References @sp 1 @paragraphindent 0 2017. @strong{Chalenski, D.A.}; Wang, K.; Tatanova, Maria; Lopez, Jorge L.; Hatchell, P.; Dutta, P.; @strong{Small airgun... (1 Reply)
Discussion started by: kristinu
1 Replies
FC-PATTERN(1)															     FC-PATTERN(1)

NAME
fc-pattern - parse and show pattern SYNOPSIS
fc-pattern [ -cdVh ] [ --config ] [ --default ] [ [ -f format ] [ --format format ] ] [ --version ] [ --help ] [ pattern [ element... ] ] DESCRIPTION
fc-pattern parses pattern (empty pattern by default) and shows the parsed result. If --config is given, config substitution is performed on the pattern before being displayed. If --default is given, default substitution is performed on the pattern before being displayed. If any elements are specified, only those are printed. OPTIONS
This program follows the usual GNU command line syntax, with long options starting with two dashes (`-'). A summary of options is included below. -c Perform config substitution on pattern. -d Perform default substitution on pattern. -f Format output according to the format specifier format. -V Show version of the program and exit. -h Show summary of options. pattern Parses and displays pattern (uses empty pattern by default). element If set, the element property is displayed for parsed pattern. SEE ALSO
FcNameParse(3) FcConfigSubstitute(3) FcDefaultSubstitute(3) FcPatternPrint(3) FcPatternFormat(3) fc-cat(1) fc-cache(1) fc-list(1) fc- match(1) fc-query(1) fc-scan(1) The fontconfig user's guide, in HTML format: /usr/share/doc/fontconfig/fontconfig-user.html. AUTHOR
This manual page was updated by Behdad Esfahbod <behdad@behdad.org>. Apr 20, 2010 FC-PATTERN(1)
All times are GMT -4. The time now is 07:55 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy