Sponsored Content
Top Forums Shell Programming and Scripting Print all lines between two keyword if a specific pattern exist Post 302952133 by Amit Joshi on Friday 14th of August 2015 01:55:12 AM
Old 08-14-2015
Print all lines between two keyword if a specific pattern exist

I have input file as below I need to check for a pattern and if it is there in file then I need to print all the lines below BEGIN and END keyword. Could you please help me how to get this in AIX using sed or awk.

Input file:
Code:
ABC
******** BEGIN *****
My name is Amit.
I am learning unix.
***** END *****
***** BEGIN *****
My name is Rahul.
***** END *****
XYZ

If I am looking for Amit then Output should be
Code:
******** BEGIN *****
My name is Amit.
I am learning unix.
***** END *****

If I am looking for Rahul then Output should be
Code:
***** BEGIN *****
My name is Rahul.
***** END *****

If I am looking for XYZ then Output should be nothing.


From below command I am able to get all the data between two keyword but not able to grep the data.
Code:
sed -n '/BEGIN/,/END/p'

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract lines of text based on a specific keyword

I regularly extract lines of text from files based on the presence of a particular keyword; I place the extracted lines into another text file. This takes about 2 hours to complete using the "sort" command then Kate's find & highlight facility. I've been reading the forum & googling and can find... (4 Replies)
Discussion started by: DionDeVille
4 Replies

2. Shell Programming and Scripting

print first few lines, then apply regex on a specific column to print results.

abc.dat tty cpu tin tout us sy wt id 0 0 7 3 19 71 extended device statistics r/s w/s kr/s kw/s wait actv wsvc_t asvc_t %w %b device 0.0 133.2 0.0 682.9 0.0 1.0 0.0 7.2 0 79 c1t0d0 0.2 180.4 0.1 5471.2 3.0 2.8 16.4 15.6 15 52 aaaaaa1-xx I want to skip first 5 line... (4 Replies)
Discussion started by: kchinnam
4 Replies

3. Shell Programming and Scripting

Print Specific lines when found specific character

Hello all, I have thousand file input like this: file1: $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ $$ | | | |$$ $$ UERT | TTYH | TAFE | FRFG |$$ $$______|______|________|______|$$ $$ | | | |$$ $$ 1 | DISK | TR1311 | 1 |$$ $$ 1 |... (4 Replies)
Discussion started by: attila
4 Replies

4. Shell Programming and Scripting

How to print Specific keyword, by using awk?

How to print Specific keyword, by using awk.? prime:root:I want output. 78 1457 10000 10000 5985 307 10000 10000 10000 10000 3760 692 6656 157 696 (4 Replies)
Discussion started by: ooilinlove
4 Replies

5. Shell Programming and Scripting

Need one liner to search pattern and print everything expect 6 lines from where pattern match made

i need to search for a pattern from a big file and print everything expect the next 6 lines from where the pattern match was made. (8 Replies)
Discussion started by: chidori
8 Replies

6. UNIX for Dummies Questions & Answers

How to Detect Specific Pattern and Print the Specific String after It?

I'm still beginner and maybe someone can help me. I have this input: the great warrior a, b, c and what i want to know is, with awk, how can i detect the string with 'warrior' string on it and print the a, b, and c seperately, become like this : Warrior Type a b c Im still very... (3 Replies)
Discussion started by: radynaraya
3 Replies

7. 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

8. Shell Programming and Scripting

sed -- Find pattern -- print remainder -- plus lines up to pattern -- Minus pattern

The intended result should be : PDF converters 'empty line' gpdftext and pdftotext?xml version="1.0"?> xml:space="preserve"><note-content version="0.1" xmlns:/tomboy/link" xmlns:size="http://beatniksoftware.com/tomboy/size">PDF converters gpdftext and pdftotext</note-content>... (9 Replies)
Discussion started by: Klasform
9 Replies

9. Shell Programming and Scripting

Print lines present in first that match second variable. And ones that does not exist in second.

I have multi line input(var1) and reference(var2) variables. How to capture lines not present in var2 but present in var1? How to capture lines present var2 but not in var1? # configuration from server var1=""" Custom JAX-RS Custom Shared Web 2.0 """ # required configuration... (6 Replies)
Discussion started by: kchinnam
6 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
PKCS7(1SSL)							      OpenSSL							       PKCS7(1SSL)

NAME
pkcs7 - PKCS#7 utility SYNOPSIS
openssl pkcs7 [-inform PEM|DER] [-outform PEM|DER] [-in filename] [-out filename] [-print_certs] [-text] [-noout] [-engine id] DESCRIPTION
The pkcs7 command processes PKCS#7 files in DER or PEM format. COMMAND OPTIONS
-inform DER|PEM This specifies the input format. DER format is DER encoded PKCS#7 v1.5 structure.PEM (the default) is a base64 encoded version of the DER form with header and footer lines. -outform DER|PEM This specifies the output format, the options have the same meaning as the -inform option. -in filename This specifies the input filename to read from or standard input if this option is not specified. -out filename specifies the output filename to write to or standard output by default. -print_certs prints out any certificates or CRLs contained in the file. They are preceded by their subject and issuer names in one line format. -text prints out certificates details in full rather than just subject and issuer names. -noout don't output the encoded version of the PKCS#7 structure (or certificates is -print_certs is set). -engine id specifying an engine (by its unique id string) will cause pkcs7 to attempt to obtain a functional reference to the specified engine, thus initialising it if needed. The engine will then be set as the default for all available algorithms. EXAMPLES
Convert a PKCS#7 file from PEM to DER: openssl pkcs7 -in file.pem -outform DER -out file.der Output all certificates in a file: openssl pkcs7 -in file.pem -print_certs -out certs.pem NOTES
The PEM PKCS#7 format uses the header and footer lines: -----BEGIN PKCS7----- -----END PKCS7----- For compatibility with some CAs it will also accept: -----BEGIN CERTIFICATE----- -----END CERTIFICATE----- RESTRICTIONS
There is no option to print out all the fields of a PKCS#7 file. This PKCS#7 routines only understand PKCS#7 v 1.5 as specified in RFC2315 they cannot currently parse, for example, the new CMS as described in RFC2630. SEE ALSO
crl2pkcs7(1) 1.0.1e 2013-02-11 PKCS7(1SSL)
All times are GMT -4. The time now is 12:21 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy