0

I have a file with several thousand lines. I'm looking to replace newline character with || (that is <space>||<space>)

I'm wanting to this via bash on Ubuntu 20.04

I've tried the following but in vain -

tr '\n' ' || ' < input.txt
tr '\n' ' \|| ' < input.txt
tr '\n' ' \|\| ' < input.txt

I'm not able to work out what I'm doing wrong. Please can someone help me spot my mistake?

phuclv
  • 37,963
  • 15
  • 156
  • 475
usert4jju7
  • 1,653
  • 3
  • 27
  • 59
  • 1
    Please add sample input (no descriptions, no images, no links) and your desired output for that sample input to your question (no comment). – Cyrus Dec 02 '21 at 23:26
  • 1
    See: [How to replace one character with two characters using tr](https://stackoverflow.com/q/18365482/3776858) – Cyrus Dec 02 '21 at 23:34
  • 1
    Does this answer your question? [How to replace one character with two characters using tr](https://stackoverflow.com/questions/18365482/how-to-replace-one-character-with-two-characters-using-tr) – phuclv Dec 03 '21 at 03:47

1 Answers1

0

Actually, just after posting this question, I worked this out. Leaving the answer here if someone someday finds it helpful

perl -p -e 's/\n/ || / ' input.txt
usert4jju7
  • 1,653
  • 3
  • 27
  • 59