Grep for string, but within mentioned bounds


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grep for string, but within mentioned bounds
# 1  
Old 01-29-2016
Grep for string, but within mentioned bounds

Hi,

I've been trying to filter a file which has several repetitions of lines which looks as follows:

Code:
('hello
My name is
jamie
blabla
xyz>>)

Each line has different values in them. I want grep or awk or sed to treat everything within the (' and >>) as one line and then filter for a single word, for example jamie.

Any ideas how to do this?

PS:

I had tried a solution based on the following awk '/START:/{if (NR!=1)print "";next}{print $0}END{print "";}. However, the output still seems to be in separate lines...

I above gives me a solution as follows:

Code:
My name is
jamie
blabla
xyz>>)

My name is
joan
blabla
blabla
xyz>>)

Is there an easy way to merge lines not separated by a blank line into a single line?
Thanks.

Last edited by jamie_123; 01-29-2016 at 10:50 AM..
# 2  
Old 01-29-2016
Please be way more detailed and specific! Are those records separated by a blank line? What should the output look like?

Based on wild guesses, I came up with
Code:
awk '{X = X FS $0} />>\)/ {if (X ~ "jamie") print X; X = ""}' file
 ('hello My name is jamie blabla xyz>>)

Does this satisfy your request?
# 3  
Old 01-29-2016
Quote:
Is there an easy way to merge lines not separated by a blank line into a single line?
Code:
awk -vRS=  '{gsub(/\n/, " ")}1' INPUTFILE

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

-Warray-bounds option to GCC compiler

What exactly is the -Warray-bounds option to the GCC compiler supposed to warn about? the man page states: ~ g++ --version g++ (GCC) 7.3.1 20180130 (Red Hat 7.3.1-2) Copyright (C) 2017 Free Software Foundation, Inc.Thank you. (14 Replies)
Discussion started by: milhan
14 Replies

2. UNIX for Beginners Questions & Answers

Can I combine below mentioned grep commands using OR (when searching strings having spaces)

Command 1: $script | grep 'Write to ECC( SSID=MARGIN)' Command 2: $script | grep 'is not greater than existing logical processing' The above commands run my script and search the mentioned strings but I do not want to run my script twice. It is increasing run time. Can someone tell me... (3 Replies)
Discussion started by: Tanu
3 Replies

3. Shell Programming and Scripting

Grep for all ip addresses mentioned in all files in a Directory

I wish to traverse all files and folders under a given directory say "/tmp/configuration" and for all ip address mentioned therein. I tried find ./ -type f | xargs grep "*.*.*.*" but it does not populated the correct results. Can you please suggest. (1 Reply)
Discussion started by: mohtashims
1 Replies

4. Shell Programming and Scripting

Grep string in files and list file names that contain the string

Hi, I have a list of zipped files. I want to grep for a string in all files and get a list of file names that contain the string. But without unzipping them before that, more like using something like gzcat. My OS is: SunOS test 5.10 Generic_142900-13 sun4u sparc SUNW,SPARC-Enterprise (8 Replies)
Discussion started by: apenkov
8 Replies

5. Shell Programming and Scripting

grep exact string from files and write to filename when string present in file

I am attempting to grep an exact string from a series of files within a directory and append that output to the filename when it is present in the file. I've been after this all day with no luck. Thanks for your help in advance :wall:. (4 Replies)
Discussion started by: JC_1
4 Replies

6. Shell Programming and Scripting

Grep a string from input file and delete next three lines including the line contains string in xml

Hi, 1_strings file contains $ cat 1_strings /home/$USER/Src /home/Valid /home/Review$ cat myxml <projected value="some string" path="/home/$USER/Src"> <input 1/> <estimate value/> <somestring/> </projected> <few more lines > <projected value="some string" path="/home/$USER/check">... (4 Replies)
Discussion started by: greet_sed
4 Replies

7. UNIX for Dummies Questions & Answers

| help | unix | grep - Can I use grep to return a string with exactly n matches?

Hello, I looking to use grep to return a string with exactly n matches. I'm building off this: ls -aLl /bin | grep '^.\{9\}x' | tr -s ' ' -rwxr-xr-x 1 root root 632816 Nov 25 2008 vi -rwxr-xr-x 1 root root 632816 Nov 25 2008 view -rwxr-xr-x 1 root root 16008 May 25 2008... (7 Replies)
Discussion started by: MykC
7 Replies

8. Programming

array bounds and mem leak tool

Is there any freeware to find out array bounds static and dynamic ways in Solaris 10. (1 Reply)
Discussion started by: satish@123
1 Replies

9. Programming

how to avoid the segfault from Address 0x1cd00000103 out of bounds

After allocating memory for some variables, segfault is often to happen, due to the same reason: Address 0x1cd00000103 out of bounds It is welcome to recommend some treatments. Thanks e.g. is_done = 0x1cd00000103 <Address 0x1cd00000103 out of bounds>, hood = 0x23c00000247, c =... (11 Replies)
Discussion started by: cdbug
11 Replies

10. UNIX for Advanced & Expert Users

crontab: error on previous line; number out of bounds.

Hi, I am trying to set up a cron job for every Friday at 6:00 p.m. and got an error: "/var/tmp/aaaa29638" 1 line, 73 characters 00 18 00 0 5 /app/test/backup.ksh crontab: error on previous line; number out of bounds. Any ideas? Thanks! (1 Reply)
Discussion started by: oradbus
1 Replies
Login or Register to Ask a Question