?
Solved

Grep string from multiline

Posted on 2003-12-10
1
Medium Priority
?
1,032 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 1

Accepted Solution

by:
mbekker earned 200 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

Technology Partners: 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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

771 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