Solved

Grep string from multiline

Posted on 2003-12-10
1
1,028 Views
Last Modified: 2013-12-26
Hi,

I need to use grep to gerp out a string from 2 lines. The file like:
ABCDEF123456
890YEAHYEAHD
ABCDEFA23AAA
890YEAHYEAHD
ABCDEF654321
890YEAHYEAHD

The result should be:
ABCDEF123456890YEAHYEAHD
ABCDEF654321890YEAHYEAHD
(The 2 lines with 8 continuous digit.)

How can I do that?
0
Comment
Question by:matchz
1 Comment
 
LVL 1

Accepted Solution

by:
mbekker earned 50 total points
ID: 9919865
Hi matchz,

The following works for above example:

sed 's/[^0-9]$/&#/' filename | \
 tr '#\n' '\n#' | \
 sed 's/#//g' | \
 grep "[^0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9]"

Only this one greps 9-digit numbers, in your example you have nine digits. If you want for example at least 8 digits the [^0-9] parts before and after could be removed.

It's not a neat solution, but it works. And as far as I know there is no way to grep out of two lines with the grep command only.

Good luck!
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question