Home > Back-end >  How to print a line which has backslash \ at the end of line to split lengthy line to multiple line
How to print a line which has backslash \ at the end of line to split lengthy line to multiple line

Time:10-05

I have a file that has text files references in multiple lines with a backslash at the end of each line, how to read "TEXT_FILES with data" as a single line.

TEXT_FILES == file1.txt file2.txt  file3.txt \         #SET1
              file4.txt \                              #SET2
              file5.txt  file6.txt \                   #SET3
              file7.txt                                #SET4

expected output to print in terminal:"

TEXT_FILES == file1.txt file2.txt file3.txt file4.txt file5.txt file6.txt file7.txt

CodePudding user response:

Assuming #SETX to be not a part of the file to be analysed, you could eventually try something like this.

awk '{gsub(/[\\ ] /," ")}1' FS='\' ORS="" input_file.txt

CodePudding user response:

When all backslashes indicate the and of the line, use

sed -z 's/\\[^\n]*\n//g' file

When you want to remove the spaces at the start of the line, you can use

sed -z 's/\\[^\n]*\n *//g' file
  • Related