Grep/awk using a begin search pattern and end search pattern


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Grep/awk using a begin search pattern and end search pattern
# 1  
Old 05-10-2018
Grep/awk using a begin search pattern and end search pattern

I have this fileA

Code:
TEST FILE ABC
this file contains ABC;

TEST FILE DGHT this file contains DGHT;

TEST FILE 123
this file contains ABC,
this file contains DEF,
this file contains XYZ,
this file contains KLM
;

I want to have a fileZ that has only (begin search pattern for will be "TEST FILE 123" and end search pattern will be ";")

Code:
TEST FILE 123
this file contains ABC,
this file contains DEF,
this file contains XYZ,
this file contains KLM
;

Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 05-10-2018 at 05:24 AM.. Reason: Added CODE tags.
# 2  
Old 05-10-2018
Hello vbabz,

Welcome to UNIX and LINUX forums. Kindly use code tags for your samples shown in your post. In case your actual Input_file is same as shown sample then following may help you on same.
Code:
sed -n '/TEST FILE 123/,/;/p'  Input_file

Thanks,
R. Singh
# 3  
Old 05-10-2018
Thank you
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Pattern Search with grep

Hello, I have a bunch of zip files like SS_SAMPLE_101_123.zip SS_101_123.zip SS_SAMPLE_121_345.zip SS_SAMPLE_222_678.zip SS_123_890.zip SS_.zip The 'ls' should search and list the files such as SS_101_123.zip and SS_123_890.zip alone. Could you please guide me with this.... (5 Replies)
Discussion started by: tinufarid
5 Replies

2. Shell Programming and Scripting

Pattern search using grep command !

Hi, I am trying to do pattern search using grep command. But i donot know what mistake i'm doing. I am not getting the expected Result. could any one please help me out? $ cat b.ksh AasdjfhB 57834B 86234B 472346B I want to print the line which is starting with either A or 8 and... (10 Replies)
Discussion started by: nikesh29
10 Replies

3. Shell Programming and Scripting

Awk to match a pattern and perform a search after the first pattern

Hello Guyz I have been following this forum for a while and the solutions provided are super useful. I currently have a scenario where i need to search for a pattern and start searching by keeping the first pattern as a baseline ABC DEF LMN EFG HIJ LMN OPQ In the above text i need to... (8 Replies)
Discussion started by: RickCharles
8 Replies

4. HP-UX

recusrise pattern search with grep

Am new on hp-ux .. Found missing recursive pattern search grep -iR option that's there on Linux . Is any one know any way with grep or any advance command available on hp-ux using which i can search a word say "DbFnamesDatLimit" in all files under /etc on hp-ux in single step . my /etc... (3 Replies)
Discussion started by: Shirishlnx
3 Replies

5. UNIX for Dummies Questions & Answers

One liner pattern search with awk/sed/grep

I have an array containing bunch of characters. I have to check this array for specific character and if "Not Found than" use a goto statement to go to USAGE set options = (A B C D E F) @ i = 0 while ($i <= ${#options}) if ($options != "F" || $options != "D") then goto USAGE endif @... (1 Reply)
Discussion started by: dixits
1 Replies

6. Shell Programming and Scripting

search for a pattern using grep

Hi I am facing the below problem. I have set of lines in which i have to search for only the line which matches with the pattren "/" only. input:- /*+ some text */ /*+ some text */ /* Remove rows from a table of survey results. */ /* Add a survey respondent's name and answers. */ /*... (7 Replies)
Discussion started by: manasa_vs
7 Replies

7. Shell Programming and Scripting

Help to search multiple pattern in file with grep/sed/awk

Hello All, I have a file which is having below type of data, Jul 19 2011 | 123456 Jul 19 2011 | 123456 Jul 20 2011 | 123456 Jul 20 2011 | 123456 Here I wanted to grep for date pattern as below, so that it should only grep "Jul 20" OR "Jul ... (9 Replies)
Discussion started by: gr8_usk
9 Replies

8. UNIX for Dummies Questions & Answers

Dump to another file for a begin and end Pattern

Hi All , I am newbie to linux shell scripting , below are the contents of my log file , i want the lines between a begin pattern and a end pattern for an instance , my begin Pattern is "Transaction Begins for Usr" and end pattern is "Transaction Ends for Usr" into another file Sample file... (1 Reply)
Discussion started by: SARAVANANE
1 Replies

9. Shell Programming and Scripting

search a pattern and if pattern found insert new pattern at the begining

I am trying to do some thing like this .. In a file , if pattern found insert new pattern at the begining of the line containing the pattern. example: in a file I have this. gtrow0unit1/gctunit_crrownorth_stage5_outnet_feedthru_pin if i find feedthru_pin want to insert !! at the... (7 Replies)
Discussion started by: pitagi
7 Replies

10. Shell Programming and Scripting

search pattern by grep

hai folks, i am vijay very new to this website. My query: Search patterns from root directory to all directories by using grep (3 Replies)
Discussion started by: vijaysabari
3 Replies
Login or Register to Ask a Question