Script to print first and last line have two pattern


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to print first and last line have two pattern
Prev   Next
# 1  
Old 11-10-2009
Script to print first and last line have two pattern

Hello Guys,
I have file like
aaa
bbb
Line 1
cc
dd
Ser Nu 11223
ee
ff
Line 2
hh
hh
Ser Nu 44556
ii
jj

I need to match line starting with Line and Ser and only display them like

Line 1 Ser Nu 11223 | Line 2 Ser Nu 44556

The number of lines can be multiple Line 1 Line 2 Line 3 Line 4 ........Line 1000

---------- Post updated at 05:58 PM ---------- Previous update was at 04:44 PM ----------

sed -n '/Line/,/Ser/p'
this prints all the lines between the Line and Ser.
A small tweek is needed.........any takers.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Reading a file line by line and print required lines based on pattern

Hi All, i want to write a shell script read below file line by line and want to exclude the lines which contains empty value for MOUNTPOINT field. i am using centos 7 Operating system. want to read below file. # cat /tmp/d5 NAME="/dev/sda" TYPE="disk" SIZE="60G" OWNER="root"... (4 Replies)
Discussion started by: balu1234
4 Replies

2. Shell Programming and Scripting

How to print previous line of multiple pattern matched line?

Hello, I have below format log file, Comparing csv_converted_files/2201/9747.1012H67126.5077292103609547345.csv and csv_converted_files/22019/97447.1012H67126.5077292103609547345.csv Comparing csv_converted_files/2559/9447.1012H67126.5077292103609547345.csv and... (6 Replies)
Discussion started by: arvindshukla81
6 Replies

3. Shell Programming and Scripting

Match Pattern and print pattern and multiple lines into one line

Hello Experts , require help . See below output: File inputs ------------------------------------------ Server Host = mike id rl images allocated last updated density vimages expiration last read <------- STATUS ------->... (4 Replies)
Discussion started by: tigerhills
4 Replies

4. Shell Programming and Scripting

Print only next pattern in a line after a pattern match

I have 2013-06-11 23:55:14 1Umexd-0004cm-IG <= user@domain.com I need sed/awk operation on this, so that it should print the very next pattern only after the the pattern mach <= ie only print user@domain.com (7 Replies)
Discussion started by: anil510
7 Replies

5. Shell Programming and Scripting

Script to compare pattern and print a different pattern in each line

Hi, I am writing a shell script to parse some files, and gather data. The data in the files is displayed as below. .......xyz: abz: ......qrt: .... .......xyz: abz: ......qrt: ... I have tried using awk and cut, but the position of these values keep changing, so I wasn't able to get... (2 Replies)
Discussion started by: Serena
2 Replies

6. Shell Programming and Scripting

Print between multi line pattern

Hi, I have a file with text like this .SET WIDTH 10000 .SET MAXERROR 1 insert into new_db SELECT * FROM some_db ; +---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+- .SET WIDTH 10000... (3 Replies)
Discussion started by: sol_nov
3 Replies

7. Shell Programming and Scripting

Print Line if next line Match a pattern

Hi All, Does anyone know how to print 1H1A....... in peal script print line ^1H1A....... if next line equal 5R0RECEIPT.... Thank for help:D Cat st.txt 1H1A-IN-11-5410-0009420|1010047766|dsds|1|N|IN|IN|000000|1||N|<<<line match 5R0RECEIPT| 5R0RECEIPT|... (2 Replies)
Discussion started by: kittiwas
2 Replies

8. Programming

Print specific pattern line in c++

Input file: @HWI-BRUNOP1_header_1 GACCAATAAGTGATGATTGAATCGCGAGTGCTCGGCAGATTGCGATAAAC +HWI-BRUNOP1_header_1 TNTTJTTTETceJSP__VRJea`_NfcefbWe Desired output file: >HWI-BRUNOP1_header_1 GACCAATAAGTGATGATTGAATCGCGAGTGCTCGGCAGATTGCGATAAAC >HWI-BRUNOP1_header_2... (10 Replies)
Discussion started by: cpp_beginner
10 Replies

9. Shell Programming and Scripting

match a pattern and print the line once

Hi, I have a xml file <cisco:name> <cisco:mdNm>Cisco Device 7500 A Series</cisco:mdNm> <cisco:meNm>10.1.100.19</cisco:meNm> <cisco:ehNm>/shelf=1</cisco:ehNm> <cisco:subname> <cisco:meNm>10.1.100.19</cisco:meNm> <cisco:sptp>Cisco PortA Series</cisco:sptp> ... (11 Replies)
Discussion started by: bhagirathi
11 Replies

10. Shell Programming and Scripting

Print the line within the search pattern

Hi Guys, I had file as typedef struct { char TrailerType1; char TrailerTxt1; }Trailer; typedef struct { char PfigMoneyType; char PfigMoneyvalue; }PfigMoney; i need to print the lines within the search pattern. if i give the search pattern as... (3 Replies)
Discussion started by: manosubsulo
3 Replies
Login or Register to Ask a Question
POE::Filter::Line(3pm)					User Contributed Perl Documentation				    POE::Filter::Line(3pm)

NAME
POE::Filter::Line - serialize and parse terminated records (lines) SYNOPSIS
#!perl use POE qw(Wheel::FollowTail Filter::Line); POE::Session->create( inline_states => { _start => sub { $_[HEAP]{tailor} = POE::Wheel::FollowTail->new( Filename => "/var/log/system.log", InputEvent => "got_log_line", Filter => POE::Filter::Line->new(), ); }, got_log_line => sub { print "Log: $_[ARG0] "; } } ); POE::Kernel->run(); exit; DESCRIPTION
POE::Filter::Line parses stream data into terminated records. The default parser interprets newlines as the record terminator, and the default serializer appends network newlines (CR/LF, or "x0Dx0A") to outbound records. Record terminators are removed from the data POE::Filter::Line returns. POE::Filter::Line supports a number of other ways to parse lines. Constructor parameters may specify literal newlines, regular expressions, or that the filter should detect newlines on its own. PUBLIC FILTER METHODS
POE::Filter::Line's new() method has some interesting parameters. new new() accepts a list of named parameters. In all cases, the data interpreted as the record terminator is stripped from the data POE::Filter::Line returns. "InputLiteral" may be used to parse records that are terminated by some literal string. For example, POE::Filter::Line may be used to parse and emit C-style lines, which are terminated with an ASCII NUL: my $c_line_filter = POE::Filter::Line->new( InputLiteral => chr(0), OutputLiteral => chr(0), ); "OutputLiteral" allows a filter to put() records with a different record terminator than it parses. This can be useful in applications that must translate record terminators. "Literal" is a shorthand for the common case where the input and output literals are identical. The previous example may be written as: my $c_line_filter = POE::Filter::Line->new( Literal => chr(0), ); An application can also allow POE::Filter::Line to figure out which newline to use. This is done by specifying "InputLiteral" to be undef: my $whichever_line_filter = POE::Filter::Line->new( InputLiteral => undef, OutputLiteral => " ", ); "InputRegexp" may be used in place of "InputLiteral" to recognize line terminators based on a regular expression. In this example, input is terminated by two or more consecutive newlines. On output, the paragraph separator is "---" on a line by itself. my $paragraph_filter = POE::Filter::Line->new( InputRegexp => "([x0Dx0A]{2,})", OutputLiteral => " --- ", ); PUBLIC FILTER METHODS
POE::Filter::Line has no additional public methods. SEE ALSO
Please see POE::Filter for documentation regarding the base interface. The SEE ALSO section in POE contains a table of contents covering the entire POE distribution. BUGS
The default input newline parser is a regexp that has an unfortunate race condition. First the regular expression: /(x0Dx0A?|x0Ax0D?)/ While it quickly recognizes most forms of newline, it can sometimes detect an extra blank line. This happens when a two-byte newline character is broken between two reads. Consider this situation: some stream dataCR LFother stream data The regular expression will see the first CR without its corresponding LF. The filter will properly return "some stream data" as a line. When the next packet arrives, the leading "LF" will be treated as the terminator for a 0-byte line. The filter will faithfully return this empty line. It is advised to specify literal newlines or use the autodetect feature in applications where blank lines are significant. AUTHORS &; COPYRIGHTS Please see POE for more information about authors and contributors. perl v5.14.2 2012-05-15 POE::Filter::Line(3pm)