0

I have a file containing many blocks of lines. In each block, I have one numeric character of multiple digits (15353580 for instance). I need to extract all these numbers and put them as a column in a new file.

I came across this thread. The sed command does the job but does not separate the numbers from each other. Using the second example ("123 he23llo") of the most voted response, I would like to have 123-23 instead of 12323, where my '-' stands for a line break. How can I do so ?

Community
  • 1
  • 1
dada
  • 1,390
  • 2
  • 17
  • 40

1 Answers1

0

You can use this sed,

sed -e 's/[^0-9]\+/-/g' -e 's/-$//'

Example:

$ echo "123 hel43lo 23fds" | sed -e 's/[^0-9]\+/-/g' -e 's/-$//'
123-43-23
sat
  • 14,589
  • 7
  • 46
  • 65