0

When I use cat file_name.txt I get the logs in one line. How to separate each string to new line?

"Rest API SRV01""Rest API SRV02""Rest API SRV01"

Expected output:

"Rest API SRV01"
"Rest API SRV02"
"Rest API SRV01"
sk306
  • 29
  • 4
  • It'd be worth knowing the file's actual format; if it has NULs between the strings, f/e, that allows an answer that's both simpler and more reliable than your currently selected one. Use `cat -A file_name.txt` on a GNU system, or `xxd file_name.txt` more portably to get a dump that will show any hidden/nonprintable characters between your strings. – Charles Duffy Dec 23 '22 at 14:56

1 Answers1

1

One way is to replace each "" with "\n:

sed 's/\"\"/\"\n\"/g' <<< '"Rest API SRV01""Rest API SRV02""Rest API SRV01"'
"Rest API SRV01"
"Rest API SRV02"
"Rest API SRV01"
0stone0
  • 34,288
  • 4
  • 39
  • 64
  • Thx, I am doing sth like that done > test.txt && cat test.txt. How to use sed with those commands ( | or &&)? – sk306 Dec 23 '22 at 13:13
  • Not sure what your asking. Please add the command you're using (or trying to fix) to your question. – 0stone0 Dec 23 '22 at 13:15
  • 1
    done > test.txt && sed 's/\"\"/\"\n\"/g' test.txt ---> it works properly :) – sk306 Dec 23 '22 at 13:18
  • @sk306 Why have a `test.txt` at all? `done | sed ...`; even if you want the file, `done | tee test.txt | sed ...` will let `sed` process content as the while loop prints it instead of needing to wait for the loop to finish before sed can start at all. – Charles Duffy Dec 23 '22 at 14:57