-4

I need to add pipes to the following line:

10.245.1.1     0027.e391.cfc0  6975

Required output:

10.245.1.1|0027.e391.cfc0|697|5

I have tried using sed but I am a mess with regexp. Any help is appreciated.

Cyrus
  • 84,225
  • 14
  • 89
  • 153
  • 2
    please show us your sample code. We then try to fix the error. – Charlie Nov 11 '18 at 16:16
  • 3
    Welcome to SO. Stack Overflow is a question and answer site for professional and enthusiast programmers. The goal is that you add some code of your own to your question to show at least the research effort you made to solve this yourself. – Cyrus Nov 11 '18 at 17:47
  • 1
    what have you tried so far? please provide a [minimal, complete, and verifiable example](https://stackoverflow.com/help/mcve) – landru27 Nov 11 '18 at 19:02
  • Possible duplicate of [Learning Regular Expressions](https://stackoverflow.com/questions/4736/learning-regular-expressions) – Biffen Nov 12 '18 at 10:42

1 Answers1

0

I would recommend you to check out the gnu manual for regex stuff with sed https://www.gnu.org/software/sed/manual/html_node/Regular-Expressions.html

It's a very powerful tool.

The sed command you're asking for is echo '10.245.1.1 0027.e391.cfc0 6975' | sed 's/\([[:graph:]]*\)[[:blank:]]\+\([[:graph:]]*\)[[:blank:]]\+\([[:digit:]]*\)\([[:digit:]]\)/\1|\2|\3|\4/g'

For more information, visit the Link please

eleos91
  • 31
  • 5