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
LDAP_CONTROL_PAGED_RESULT(3)						 1					      LDAP_CONTROL_PAGED_RESULT(3)

ldap_control_paged_result - Send LDAP pagination control

SYNOPSIS
bool ldap_control_paged_result (resource $link, int $pagesize, [bool $iscritical = false], [string $cookie = ""]) DESCRIPTION
Enable LDAP pagination by sending the pagination control (page size, cookie...). PARAMETERS
o $link - An LDAP link identifier, returned by ldap_connect(3). o $pagesize - The number of entries by page. o $iscritical - Indicates whether the pagination is critical of not. If true and if the server doesn't support pagination, the search will return no result. o $cookie - An opaque structure sent by the server (ldap_control_paged_result_response(3)). RETURN VALUES
Returns TRUE on success or FALSE on failure. EXAMPLES
The example below show the retrieval of the first page of a search paginated with one entry by page. Example #1 LDAP pagination <?php // $ds is a valid link identifier (see ldap_connect) ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3); $dn = 'ou=example,dc=org'; $filter = '(|(sn=Doe*)(givenname=John*))'; $justthese = array('ou', 'sn', 'givenname', 'mail'); // enable pagination with a page size of 1. ldap_control_paged_result($ds, 1); $sr = ldap_search($ds, $dn, $filter, $justthese); $info = ldap_get_entries($ds, $sr); echo $info['count'] . ' entries returned' . PHP_EOL; The example below show the retrieval of all the result paginated with 100 entries by page. Example #2 LDAP pagination <?php // $ds is a valid link identifier (see ldap_connect) ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3); $dn = 'ou=example,dc=org'; $filter = '(|(sn=Doe*)(givenname=John*))'; $justthese = array('ou', 'sn', 'givenname', 'mail'); // enable pagination with a page size of 100. $pageSize = 100; $cookie = ''; do { ldap_control_paged_result($ds, $pageSize, true, $cookie); $result = ldap_search($ds, $dn, $filter, $justthese); $entries = ldap_get_entries($ds, $result); foreach ($entries as $e) { echo $e['dn'] . PHP_EOL; } ldap_control_paged_result_response($ds, $result, $cookie); } while($cookie !== null && $cookie != ''); NOTES
Note Pagination control is a LDAPv3 protocol feature. SEE ALSO
ldap_control_paged_result_response(3), RFC2696 : LDAP Control Extension for Simple Paged Results Manipulation. PHP Documentation Group LDAP_CONTROL_PAGED_RESULT(3)
All times are GMT -4. The time now is 01:45 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy