Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Vi delete line with second occurence of pattern Post 302939557 by durden_tyler on Thursday 26th of March 2015 01:53:56 PM
Old 03-26-2015
Quote:
Originally Posted by homer4all
...
Sample pattern to delete John-------Doe
Code:
Sample data:
Time--------FName---------LName
11:05-------John------------Doe
11:05-------John------------Doe
11:06-------Michael---------Lawrence
11:06-------Michale---------Lawrence

Expected result:
11:05-------John------------Doe
11:06-------Michael---------Lawrence

Why do you expect the last line to be removed?
- It is not a duplicate since "Michale" != "Michael"
- It doesn't match the pattern either.

In any case, try this:

Code:
:%s/\v^(.*John------------Doe.*)\n\1/\1/

I have tried it in vim though. It's difficult to get a hold of vi since it's almost always a link to vim in Linux/Cygwin these days.
This User Gave Thanks to durden_tyler For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl onliner to search the last line with an occurence of a pattern

Hi I need a perl onliner which seaches a line starting with a pattern(last occurence) and display it. similar to grep 'pattern' filename | tail -1 in UNIX Ex: I want to display the line starting with "cool" and which is a last occurence adadfadafadf adfadadf cool dfadfadfadfara... (4 Replies)
Discussion started by: ammu
4 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. UNIX for Dummies Questions & Answers

find pattern delete line with pattern and line above and line below

I have a file that will sometimes contain a pattern. The pattern is this: W/D FRM CHK 00 I want to find any lines with this pattern, delete those lines, and also delete the line above and the line below. (1 Reply)
Discussion started by: nickg
1 Replies

4. Shell Programming and Scripting

find pattern, delete line with pattern and line above and line below

I have a file that will sometimes contain a pattern. The pattern is this: FRM CHK 0000 I want to find any lines with this pattern, delete those lines, and also delete the line above and the line below. (4 Replies)
Discussion started by: nickg
4 Replies

5. Shell Programming and Scripting

delete line upto the nth occurence of a particular charachter.

hi all i want to delete a line upto a particular character. here is example. cp cms/images/wifi-zone.png i want to delete the line till . (cp cms/images/wifi-zone.) so the output wud be "png" only how can i do it? also please note down that dot (.) can also occur multiple... (12 Replies)
Discussion started by: kashifv
12 Replies

6. Linux

Problem editting the first occurence of a pattern in the first uncommented line

Hi I have to replace a pattern found in the first uncommented line in a file. The challenge I'm facing is there are several such similar lines but I have to edit only the first uncommented line. Eg: #this is example #/root/xyz:Old_Pattern /root/xyz:Old_Pattern /root/xyz:Old_Pattern ... (10 Replies)
Discussion started by: Stoner008
10 Replies

7. Shell Programming and Scripting

sed command to grep multiple pattern present in single line and delete that line

here is what i want to achieve.. i have a file with below contents cat fileName blah blah blah . .DROP this REJECT that . --sport 7800 -j REJECT --reject-with icmp-port-unreachable --dport 7800 -j REJECT --reject-with icmp-port-unreachable . . . more blah blah blah --dport 3306... (14 Replies)
Discussion started by: vivek d r
14 Replies

8. Shell Programming and Scripting

Match pattern and print the line number of occurence using awk

Hi, I have a simple problem but i guess stupid enough to figure it out. i have thousands rows of data. and i need to find match patterns of two columns and print the number of rows. for example: inputfile abd abp 123 abc abc 325 ndc ndc 451 mjk lkj... (3 Replies)
Discussion started by: redse171
3 Replies

9. Shell Programming and Scripting

Delete after nth occurence of string in each line

Hello, Environment: I am under Ubuntu 18.04 bionic. I have an sql file consisting of 10K lines. Objective: What I am trying to attain is to remove everything coming after 2nd tab in each line. While searching for the answer, I found two answers and both gave expected result just for the first... (2 Replies)
Discussion started by: baris35
2 Replies

10. Shell Programming and Scripting

Extract whole word preceding a specific character pattern with first occurence of the pattern

Hello. Here is a file contents : declare -Ax NEW_FORCE_IGNORE_ARRAY=(="§" ="§" ="§" ="§" ="§" .................. ="§"Here is a pattern =I want to extract 'NEW_FORCE_IGNORE_ARRAY' which is the whole word before the first occurrence of pattern '=' Is there a better solution than mine :... (3 Replies)
Discussion started by: jcdole
3 Replies
DN(3pm) 						User Contributed Perl Documentation						   DN(3pm)

NAME
X500::DN - handle X.500 DNs (Distinguished Names), parse and format them SYNOPSIS
use X500::DN; my $dn = X500::DN->ParseRFC2253 ('cn=John Doe, o=Acme\, Inc., c=US') or die; print $dn->getRFC2253String(), " "; $dn = new X500::DN (new X500::RDN ('c'=>'US'), new X500::RDN ('cn'=>'John Doe')); my $rdn0 = $dn->getRDN(0); my $c = $rdn0->getAttributeValue ('c'); NOTE
The RFC 2253 syntax is explicitely backwards in relation to the ASN.1 SEQUENCE. So the RFC 2253 string "cn=John Doe, c=US" has the same meaning as the X.500 string "c=US, cn=John Doe". The X500::DN objects keep the RDNs in X.500 order! DESCRIPTION
This module handles X.500 DNs (Distinguished Names). Currently, it parses DN strings formatted according to RFC 2253 syntax into an internal format and produces RFC 2253 formatted string from it. Methods o $object = new X500::DN (rdn, rdn, ...); Creates a DN object from zero or more arguments of type X500::RDN. o $object = X500::DN->ParseRFC2253 ('cn=John Doe, o=Acme\, Inc., c=US'); Creates a DN object from an RFC 2253 formatted DN string notation. o $object->getRFC2253String(); Returns the DN as a string formatted according to RFC 2253 syntax. o $object->getOpenSSLString(); Returns the DN as a string formatted suitable for "openssl req -subj" and "openssl ca -subj". o $object->getX500String(); Returns the DN as a string formatted according to X.500 syntax. NOTE: This is a hack, there is no definition for a X.500 string syntax! o $object->hasMultivaluedRDNs(); Returns whether the DN contains multi-valued RDNs. o $object->getRDN (num); Returns the DN's RDN at position num as an X500::RDN object. num starts with 0, which will return the first RDN in ASN.1 SEQUENCE order. o $object->getRDNs(); Returns the DN's RDNs, a list of objects of type X500::RDN, in ASN.1 SEQUENCE order. EXPORT None. BUGS
o Due to Parse::RecDescent's greedyness, white space after attribute values gets into the parsed value. It might be possible to work around this. AUTHOR
Robert Joop <yaph-070708@timesink.de> COPYRIGHT
Copyright 2002 Robert Joop. All Rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. SEE ALSO
X500::RDN, perl. HISTORY
Early 2002: First idea, discussed on comp.lang.perl.moderated April 2002: First public release, 0.15 perl v5.10.0 2007-07-08 DN(3pm)
All times are GMT -4. The time now is 03:58 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy