anyone know how can i join multiples lines using sed till the end of a file and output to another file in a single line?
The end of each line will be replaced with a special char "#".
I am using the below SED command, however it seems to remove the last 2 lines. Also not all lines are joined together.
Hello ,
doesnt work . Can you explain the logic behind it.
gaurav@localhost:~$ echo -e "hello\nHi" |perl -nle 'BEGIN{$\='#'} print'
syntax error at -e line 1, at EOF
BEGIN not safe after errors--compilation aborted at -e line 1.
Thanks for correcting me on that Bro.
Another representation of your code that works is
sed -e :a -e N -e 's/\n/#/' -e ta original_file_name >new_filename
Please correct if i am wrong.
sed '
H # append to hold
$!d # if not last line, delete and start over
g # last line, copy from hold
s/\n/#/g # replace new line with #
s/^.// # remove the first spurious new line
' infile