Sponsored Content
Top Forums Shell Programming and Scripting Search for 2 string in 2 lines with sed ? Post 302924116 by Scrutinizer on Thursday 6th of November 2014 10:54:26 AM
Old 11-06-2014
Try:
Code:
sed '/aaa/{N; /\nbbb/!s/\n/&bbb&/;}' file

Although that would not work for occurrences of aaa on the last line..


--
Also last line:
Code:
sed '/aaa/{$s/$/\
\bbb/; $!N; /\nbbb/!s/\n/&bbb&/;}' file


Last edited by Scrutinizer; 11-06-2014 at 12:12 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How can you show lines surrounding a search string?

I would like to be able to grep (or some such thing) a search argument and then display the line plus the preceding 3 lines of the file and the following 3 lines of the file. Any ideas? Thanks in advance! :D (3 Replies)
Discussion started by: robster
3 Replies

2. UNIX for Dummies Questions & Answers

Search for string and return lines above and below

Hi, I have a file with the following contents: COMPANY ABCD TRUCKER JOE SMITH TRUCK 456 PLATE A12345678 TRUCKER BILL JONES TRUCK 789 PLATE B7894561 I need to create a script or search command that will search for this string '789' in the file. This string is unique and only... (7 Replies)
Discussion started by: doza22
7 Replies

3. Shell Programming and Scripting

How to use sed to search for string and Print previous two lines and current line

Hello, Can anybody help me to correct my sed syntax to find the string and print previous two lines and current line and next one line. i am using string as "testing" netstat -v | sed -n -e '/test/{x;2!p;g;$!N;p;D;}' -e h i am able to get the previous line current line next line but... (1 Reply)
Discussion started by: nmadhuhb
1 Replies

4. Shell Programming and Scripting

search string in a file and retrieve 10 lines including string line

Hi Guys, I am trying to write a perl script to search a string "Name" in the file "FILE" and also want to create a new file and push the searched string Name line along with 10 lines following the same. can anyone of you please let me know how to go about it ? (8 Replies)
Discussion started by: sukrish
8 Replies

5. Shell Programming and Scripting

Awk - find string, search lines below string for other strings

What's the easiest way to search a file for a specific string and then look for other instances after that? I want to search for all Virtual Hosts and print out the Server Name and Document Root (if it has that info), while discarding the rest of the info. Basically my file looks like this: ...... (6 Replies)
Discussion started by: Mbohmer
6 Replies

6. Shell Programming and Scripting

replace (sed?) a string in file with multiple lines (string) from variable

Can someone tell me how I can do this? e.g: a=$(echo -e wert trewt ertert ertert ertert erttert erterte rterter tertertert ert) How do i replace the STRING with $a? I try this: sed -i 's/STRING/'"$a"'/g' filename.ext but this don' t work (2 Replies)
Discussion started by: jforce
2 Replies

7. Shell Programming and Scripting

Search a string and replace the same string above two lines?.

I need to search this "<CardinalMPI>" string and replace the same string above two lines of the string. Nov 16, 2012 12:58:34 PM INFO: Centinel LookUp ResponseXML : <CardinalMPI> <ReasonCode></ReasonCode> <ErrorDesc></ErrorDesc> <MerchantReferenceNumber></MerchantReferenceNumber>... (4 Replies)
Discussion started by: laknar
4 Replies

8. Shell Programming and Scripting

How to Search string(which is in 2 lines) in a file?

Hello, I want to search 2 lines from the file. I wanted to display all such matches. Example file: ================== Testfile is test TEST1 TEST2 testing the file string to do testing TEST1 TEST2 sample strings ================= I wanted to search the file with 2 lines " TEST1... (3 Replies)
Discussion started by: balareddy
3 Replies

9. Shell Programming and Scripting

Search String and extract few lines under the searched string

Need Assistance in shell programming... I have a huge file which has multiple stations and i wanted to search particular station and extract few lines from it and the rest is not needed Bold letters are the stations . The whole file has multiple stations . Below example i wanted to search... (4 Replies)
Discussion started by: ajayram_arya
4 Replies

10. Shell Programming and Scripting

Search for string on a range of lines

Hi, I am trying to parse a file searching for specific set of string and then within those set of strings finding a keyword. The script works the way that I intended it to be but I thought it could be a lot simpler may be. Any advice will be much appreciated. The script at the moment is as... (1 Reply)
Discussion started by: newbie_01
1 Replies
NUACLGEN(8)															       NUACLGEN(8)

NAME
nuaclgen - NUFW acl generator SYNOPSIS
nuaclgen [ --Schema eq|ineq ] [ --Aclname ACLDN ] [ --saddr NETWORK1 ] [ --daddr NETWORK2 ] [ --proto PROTONUMBER ] [ --sport P1[:P2] ] [ --dport P3[:P4] ] [ --OsName OSNAME ] [ --OsVersion OSVERSION ] [ --OsRelease OSRELEASE ] [ --AppName APPLICATION NAME ] [ --AppSig APPLI- CATION SIGNATURE ] [ --Separator SEPARATOR ] [ --jump [ACCEPT|DROP] ] [ --groups GROUPLIST ] nuaclgen [ --List ] [ --groups Id Group ] nuaclgen [ --Delete DN ] nuaclgen [ --help ] DESCRIPTION
This manual page documents the nuaclgen command. nuaclgen is an Access control list generator for the ldap backend of Nuauth, the authentication server of the NUFW package. Original packaging and informations and help can be found from http://www.nufw.org/ OPTIONS
--Schema eq|ineq Use equality schema or not (Equality schema requires dport be specified, and is the default. --AclName Acl DN Add an acl in the ldap tree with dn Acl DN --saddr Network Specify source network for the acl, with network of the form : aaa.bbb.ccc.ddd[/ee]. Default value : 0.0.0.0/0 --daddr Network Specify destination network for the acl, with network of the form : aaa.bbb.ccc.ddd[/ee]. Default value : 0.0.0.0/0 --proto Protocol number Specify protocol type for the acl --sport Source port Specify source port(s) for the Acl. NNNN:MMMM can be used to specify a port range. --dport Destination port Specify destination port(s) for the Acl. NNNN:MMMM can be used to specify a port range. --jump Decision Specify decision for the Acl. Has to be ACCEPT or DROP. --groups Groups list Specify the user group(s) on which Acl apply. Must be of the form : Group1[,Group2[,...]] --List --group Group ID List Acls for the Group ID group --Delete Dn Deletes the Acl stored in the provided Dn --help Displays a brief resume of available options and quits SEE ALSO
nufw(8) nuauth(8) AUTHOR
Nuauth was designed and coded by Eric Leblond, aka Regit (<eric@regit.org>) , and Vincent Deffontaines, aka gryzor (<vincent@gryzor.com>). Original idea in 2001, while working on NSM Ldap support. This manual page was written by Eric Leblond and copyrighted by INL (2003-2005) Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 2 as published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts. 12 mars 2007 NUACLGEN(8)
All times are GMT -4. The time now is 04:27 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy