Tag Info

New answers tagged

2

The output of each awk processed line is terminated in a linefeed (\n) which is the Unix/Linux standard. Windows/DOS expects a carriage return followed by a linefeed to mark the end of the line (\r\n). notepad will display all Linux generated files as you are currently seeing them. To resolve, pipe the output of awk through the unix2dos command, which ...


0

I managed to convert the output file's line delimiters to dos style with unix2dos. $ unix2dos my.txt unix2dos: converting file cdc_1.1.jar.txt to DOS format...


0

You require a solution in sed, and that is already given below. But I wanted to add another possibility that IMHO is just easier and faster, tr -d "\n"


0

If Holdspace is empty you can also do: sed '/\\n/G;s/\\n\(.*\)\(.\)/\2\1/;P;D' ...but uxnut's answer is already both faster and more simple, so you can take it as you will. Another extraneous possibility: INPUT | sed -n l | while read v ; do printf "${v%?}" ; done But beware, ^that translates all standard C-style \backslash escapes - like \backspace ...


1

After working myself into Sed and particularly trying to get my head around Sed's N command I came up with the following little Sed script that works for me: sed -- '$!N;s:\n:\\n:g;'"s:':'':g" The second variant of the Sed script from my question has the problem that it leaves the last line untouched if the number of lines of input happens to be odd.


0

Another awk variation awk '{ORS = /\\/? "": RS; sub(/\\$/, ""); print}' file


1

You can use awk: $ awk 'sub(/\\$/,""){printf("%s", $0);next}1' file "abc def xyz pqr"


1

while read twolines do printf %s\\n "$twolines" done <file ...which is what I suspect was the intended destiny for that file anyway. With sed you might do: sed 'N;s/\([^\\]\)\\\n/\1/;P;D' <file ...which would at least protect backslash quoted quotes, though it misses backslash quoted backslash quoted quotes. Yeah, it's kind of a nightmare ...


0

The shorter solution seems to be with perl: perl -pe 's/\\\n//'


7

You should be able to use sed -e :a -e '/\\$/N; s/\\\n//; ta' See Peter Krumins' Famous Sed One-Liners Explained, Part I, 39. Append a line to the next if it ends with a backslash "\".



Top 50 recent answers are included