Sponsored Content
Top Forums Shell Programming and Scripting How to print different multiple lines after two patterns? Post 302964976 by liuzhencc on Thursday 21st of January 2016 01:48:04 PM
Old 01-21-2016
How to print different multiple lines after two patterns?

Hello,

I need to print some lines as explained below,
TXT example
Code:
1111
2222
3333
4444
5555
6666
7777
8888
6666
9999
1111
2222
3333
4444
5555
6666
7777
8888
6666
9999

Let's say I have two patterns 1111 and 6666 and one variable n (dynamic line numbers depending on file). Assume n=2 here, I want to print "2" lines after 1111 including the pattern 1111 and the second pattern line in the original order. The output should looks like,

Code:
1111
2222
3333--the above two line after first pattern
6666
6666
1111
2222
3333--the above two line after first pattern
6666
6666

I tried with grep -A2 -e '1111' -e '6666' TXT. It did the job partly right because it also prints two lines after the second pattern "6666", which are not wanted.

I thank you very much for your help!

Zhen
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find multiple patterns on multiple lines and concatenate output

I'm trying to parse COBOL code to combine variables into one string. I have two variable names that get literals moved into them and I'd like to use sed, awk, or similar to find these lines and combine the variables into the final component. These variable names are always VAR1 and VAR2. For... (8 Replies)
Discussion started by: wilg0005
8 Replies

2. Shell Programming and Scripting

print lines which match multiple patterns

Hi, I have a text file as follows: 11:38:11.054 run1_rdseq avg_2-5 999988.0000 1024.0000 11:50:52.053 run3_rdrand 999988.0000 1135.0 128.0417 11:53:18.050 run4_wrrand avg_2-5 999988.0000 8180.5833 11:55:42.051 run4_wrrand avg_2-5 999988.0000 213.8333 11:55:06.053... (2 Replies)
Discussion started by: annazpereira
2 Replies

3. Shell Programming and Scripting

Need to print between patterns AND a few lines before

I need to print out sections (varying numbers of lines) of a file between patterns. That alone is easy enough: sed -n '/START/,/STOP/' I also need the 3 lines BEFORE the start pattern. That alone is easy enough: grep -B3 START But I can't seem to combine the two so that I get everything between the... (2 Replies)
Discussion started by: Finja
2 Replies

4. Shell Programming and Scripting

How to print only lines in between patterns?

Hi, I want to print only lines (green-italic lines) in between first and last strings in column 9. there are different number of lines between each strings. 10 AUGUSTUS exon 4558 4669 . - . 10.g1 10 AUGUSTUS exon 8771 8889 . ... (6 Replies)
Discussion started by: jamo
6 Replies

5. Shell Programming and Scripting

Print all lines between patterns

Hi Gurus, I have a requirement where I need to display all lines between 2 patterns except the line where the first pattern in it. I tried the following command using awk but it is printing all lines except the lines where the 2 patterns exist. awk '/TRANSF_/{ P=1; next } /Busy/ {exit} P'... (9 Replies)
Discussion started by: svajhala
9 Replies

6. Shell Programming and Scripting

Perl : to print the lines between two patterns

Hello experts, I have a text file from which I need to print all the lines between the patterns. Could anyone please help me with the perl script. names.txt ========= Badger Bald Eagle Bandicoot Bangle Tiger Barnacle Barracuda Basilisk Bass Basset Hound Beetle Beluga... (7 Replies)
Discussion started by: scriptscript
7 Replies

7. Shell Programming and Scripting

Print between multiple patterns

Hello Gurus, I have a file this Dir Path 1 Connection pool="somename"; "DataSource Name"="DS name"; Password="pwd"; User Id="uid";some other fields Dir Path2 Password="pwd2"; User id="uid2"; Connection pool="somename2"; "datasource name"="DS name2";some other fields. Under each dir... (14 Replies)
Discussion started by: sirababu
14 Replies

8. Shell Programming and Scripting

Match 2 different patterns and print the lines

Hi, i have been trying to extract multiple lines based on two different patterns as below:- file1 @jkm|kdo|aas012|192.2.3.1 blablbalablablkabblablabla sjfdsakfjladfjefhaghfagfkafagkjsghfalhfk fhajkhfadjkhfalhflaffajkgfajkghfajkhgfkf jahfjkhflkhalfdhfwearhahfl @jkm|sdf|wud08q|168.2.1.3... (8 Replies)
Discussion started by: redse171
8 Replies

9. UNIX for Beginners Questions & Answers

Delete multiple lines between blank lines containing two patterns

Hi all, I'm looking for a way (sed or awk) to delete multiple lines between blank lines containing two patterns ex: user: alpha parameter_1 = 15 parameter_2 = 1 parameter_3 = 0 user: alpha parameter_1 = 15 parameter_2 = 1 parameter_3 = 0 user: alpha parameter_1 = 16... (3 Replies)
Discussion started by: ce9888
3 Replies

10. UNIX for Beginners Questions & Answers

How to print lines from a files with specific start and end patterns and pick only the last lines?

Hi, I need to print lines which are matching with start pattern "SELECT" and END PATTERN ";" and only select the last "select" statement including the ";" . I have attached sample input file and the desired input should be as: INPUT FORMAT: SELECT ABCD, DEFGH, DFGHJ, JKLMN, AXCVB,... (5 Replies)
Discussion started by: nani2019
5 Replies
lldptool(8)							       Linux							       lldptool(8)

NAME
lldptool - manage the LLDP settings and status of lldpad SYNOPSIS
lldptool <command> [options] [argument] DESCRIPTION
lldptool is used to query and configure lldpad. It connects to the client interface of lldpad to perform these operations. lldptool will operate in interactive mode if it is executed without a command. In interactive mode, lldptool will also function as an event listener to print out events as they are received asynchronously from lldpad. It will use libreadline for interactive input when available. OPTIONS
-i [ifname] specifies the network interface to which the command applies. Most lldptool commands require specifying a network interface. -V [tlvid] specifies the TLV identifier The tlvid is an integer value used to identify specific LLDP TLVs. The tlvid value is the Type value for types not equal to 127 (the organizationally specific type). For organizationally specific TLVs, the tlvid is the value represented by the 3 byte OUI and 1 byte subtype - where the subtype is the lowest order byte of the tlvid. The tlvid can be entered as a numerical value (e.g. 10 or 0xa), or for supported TLVs, as a keyword. Review the lldptool help out- put to see the list of supported TLV keywords. -n "neighbor" option for commands which can use it (e.g. get-tlv) -g [bridge scope] specify the bridge scope this command operates on. Allows to set and query all LLDP TLV modules for "nearest_bridge" (short: "nb"), "nearest_customer_bridge" ("ncb") and "nearest_nontpmr_bridge" ("nntpmrb") group mac addresses. Configurations are saved into inde- pendent sections in lldpad.conf. If no bridge scope is supplied this defaults to "nearest bridge" to preserve the previous behav- iour. -c <argument list> "config" option for TLV queries. Indicates that the query is for the configuration elements for the specified TLV. The argument list specifies the specific elements to query. If no arguments are listed, then all configuration elements for the TLV are returned. -r show raw client interface messages -R show only raw Client interface messages COMMANDS
license show license information -h, help show usage information -v, version show version information -S, stats get LLDP statistics for the specified interface -t, get-tlv get TLV information for the specified interface -T, set-tlv set TLV information for the specified interface -l, get-lldp get LLDP parameters for the specified interface -L, set-lldp set LLDP parameters for the specified interface -p, ping display the process identifier of the running lldpad process -q, quit exit from interactive mode ARGUMENTS
This section lists arguments which are available for administration of LLDP parameters. Arguments for basic TLV's (non-organizationally specific TLVs) are also described. See the SEE ALSO section for references to other lldptool man pages which contain usage details and arguments for various organizationally specific TLVs. adminStatus Argument for the get-lldp/set-lldp commands. Configures the LLDP adminStatus parameter for the specified interface. Valid values are: disabled, rx, tx, rxtx enableTx Argument for the get-tlv/set-tlv commands. May be applied per interface for a specified TLV. Valid values are: yes, no. If the DCBX TLV enableTx is set to no, then all of the DCB feature TLVs DCBX advertise settings will be turned off as well. Setting enableTx to yes for a DCBX TLV will not affect the DCBX advertise settings. ipv4 Argument for the get-tlv/set-tlv commands with respect to the Management Address TLV. The get command will retrieve the configured value. Set values take the form of an IPv4 address: A.B.C.D ipv6 Argument for the get-tlv/set-tlv commands with respect to the Management Address TLV. The get command will retrieve the configured value. Set values take the form of an IPv6 address: 1111:2222:3333:4444:5555:6666:7777:8888 and various shorthand variations. EXAMPLES
Configure LLDP adminStatus to Receive and Transmit for interface eth2 lldptool -L -i eth2 adminStatus=rxtx lldptool set-lldp -i eth2 adminStatus=rxtx Query the LLDP adminStatus for interface eth3 lldptool -l -i eth3 adminStatus lldptool get-lldp -i eth3 adminStatus Query the LLDP statistics for interface eth3 lldptool -S -i eth3 adminStatus lldptool stats -i eth3 adminStatus Query the local TLVs which are being transmitted for a given interface: lldptool -t -i eth3 lldptool get-tlv -i eth3 Query the received neighbor TLVs received on a given interface: lldptool -t -n -i eth3 lldptool get-tlv -n -i eth3 Query the value of the System Description TLV as received from the neighbor on a given interface: lldptool -t -n -i eth3 -V sysDesc lldptool get-tlv -n -i eth3 -V 6 Disable transmit of the IEEE 802.3 MAC/PHY Configuration Status TLV for a given interface: lldptool -T -i eth3 -V macPhyCfg enableTx=no lldptool set-tlv -i eth3 -V 0x120f01 enableTx=no Query value of the transmit setting for the Port Description TLV for a given interface: lldptool -t -i eth3 -V portDesc -c enableTx lldptool get-tlv -i eth3 -V 4 -c enableTx Set a Management Address TLV on eth3 to carry IPv4 address 192.168.10.10 lldptool -T -i eth3 -V mngAddr ipv4=192.168.10.10 Set a Management Address TLV on eth3 to carry IPv6 address ::192.168.10.10 lldptool -T -i eth3 -V mngAddr ipv6=::192.168.10.10 Get the configured IPv4 address for the Management Address TLV on eth3 lldptool -t -i eth3 -V mngAddr -c ipv4 Get all configured attributes for the Management Address TLV on eth3 lldptool -t -i eth3 -V mngAddr -c Enable transmit of the Edge Virtual Bridging TLV for interface eth4 lldptool -i eth4 -T -V evbCfg enableTx=yes Enable transmit of VDP for interface eth4 lldptool -i eth4 -T -V vdp enableTx=yes Display process identifier of lldpad lldptool -p SEE ALSO
lldptool-dcbx(8), lldptool-ets(8), lldptool-pfc(8), lldptool-app(8), lldptool-med(8), lldptool-vdp(8), lldptool-evb(8), lldptool-evb22(8), dcbtool(8), lldpad(8) COPYRIGHT
lldptool - LLDP agent configuration utility Copyright(c) 2007-2012 Intel Corporation. Portions of lldptool are based on: hostapd-0.5.7 Copyright (c) 2004-2008, Jouni Malinen <j@w1.fi> LICENSE
This program is free software; you can redistribute it and/or modify it under the terms and conditions of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. The full GNU General Public License is included in this distribution in the file called "COPYING". SUPPORT
Contact Information: open-lldp Mailing List <lldp-devel@open-lldp.org> open-lldp August 2012 lldptool(8)
All times are GMT -4. The time now is 04:45 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy