0

How do we remove newlines in a test.txt file so that the text now appears on a single line using tr,awk or sed?

E.g

My name is mo
Learning linux
live in CAD

If I want that text to appear on one line and save it to a new file called passed.txt. What command should I run?

TylerH
  • 20,799
  • 66
  • 75
  • 101
momo86
  • 1

1 Answers1

0

With awk:

awk '{ printf "%s",$0 }' file > passed.txt # print each line ($0) of file with no new lines

With tr:

tr -d '\n' < file > passed.txt # Use -d to delete new lines (\n)

xargs and printf is also an option:

xarg printf "%s" < file > passed.txt # Redirect file into printf and print each default space variable without new lines.

Output is redirected to passed.txt with each example

Raman Sailopal
  • 12,320
  • 2
  • 11
  • 18