Capture Numbers in File and Save Answer (Linux)

Asked

Viewed 59 times

0

I have a file with the following data:

XXZ 000000000000012 MARCIO
XXZ 000000000000022 NILSON
XXZ 000000000000032 WALTER
XXZZZ 000000000000042 CARLOS
XXXZZZ 000000000000000 MARIA

I would like to skip the first characters and capture after space the numbers and save in a file with the answer.

1 answer

2


sed -r 's/.* ([0-9]{14}).*/\1/' exemplo > saida

where:

  • .* takes a string completed by space
  • ([0-9]{14}) pick and hold (in 1) a sequence of 14 digits
  • .* catch the rest of the line
  • s/.../\1/ and replaces the previous ones with the quard digits

By the way using grep we can search and extract sequences of 14 digits

grep -Po '\d{14}' exemplo > saida
  • Thanks @Jjoao! It worked!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.