{ads}

Joining lines of text on Linux



February 09, 2023 at 11:36PM

There are number of ways to join multiple lines of text and change delimiters if needed. This article shows two of the easier ways to do this and explains the commands.

Using the tr command

The tr command is quite versatile. It’s used to make many types of changes to text files, but it can also flatten multiple lines into one by replacing newline characters with blanks. It does, however, remove the final newline as well. Note the $ prompt at the end of the second line. That's a clue!

$ tr '\n' ' ' < testfile
This is a file that I can use for testing. $
$ tr '\n' ' ' < testfile > newfile

To fix this problem, you can add a newline to the end of the file with an echo command like this:

To read this article in full, please click here



from Network World https://ift.tt/9oEibw4

0 Response to "Joining lines of text on Linux"

Post a Comment

Article Top Ads

Central Ads Article 1

Middle Ads Article 2

Article Bottom Ads