PDA

View Full Version : [SOLVED] sed grep a pattern



MikeCyber
December 1st, 2012, 10:09 AM
Hi
I want to extract from a *.txt and write to another file.
It consists of 12 numbers and/or letters without spaces or anything else between.
Those numbers are on each line and I only want those to extract to another file also each on a line.
Many thanks
Michael

Lars Noodén
December 1st, 2012, 10:45 AM
Well your answer will probably use grep or awk to redirect to a file. But first, can you provide some sample data along with the detailed selection criteria? Without seeing the data, it is very hard accurately guess.

MikeCyber
December 1st, 2012, 11:58 AM
Hi Lars
some lines only have an email and the number/letters:

asom@sme.com 3232B232323232vNvV

Other lines look alike:

"05/05/2007" "16:15:48" "MESZ" "Fredric" "Zahlung f�r Warenkorb empfangen" "Abgeschlossen" "EUR" "9.00" "-0.70" "8.30" "Arld@al.com" "mich@gm.ch" "3232B232323232vNvV" "" ""

And I want to extract only: 3232B232323232vNvV
to a new txt file/line.
Many thanks

Vaphell
December 1st, 2012, 12:39 PM
try

grep -Eo '\b[a-zA-Z0-9]{18}\b'

MikeCyber
December 2nd, 2012, 08:52 AM
Great, many thanks.