Solved

Grep string from multiline

Posted on 2003-12-10
1
1,030 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Perl Awk Need Help 3 139
notReplace  challenge 53 151
Modbus - whats the maximum I can store in one register? 4 82
sumHeights  challenge 17 79
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

726 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