sed replace end of line with character
Hi, if I have a file with 10 lines, and all I want is to join the list of lines together in my file into a single line, by the characer '&', can someone explain why I need to do the following.
Code:
sed ':a;N;$!ba;s/\n/\&/g' Code:
sed 's/\n/\&/g' |
because sed is line based, to doesn't see the \n character, as that delimits the lines it processes.
tr would work easily though... Code:
tr '\n' '&' |
Quote:
Have a look here: How to match newlines in sed BTW: Wouldn't this be a better solution: Code:
cat infile | tr '\n' '&' |
Ah damn. Thanks guys. Knew 'sed' is line based but got lost in within what I was trying to do.
|
I like to use paste for this transformation.
InFile ... Code:
albert Code:
paste -sd\& $InFile > $OutFile Code:
albert&bernard&charles&david&edward&frank&george&henry&irving&john |
Code:
awk 'ORS="&"' file |
Minor nitpick
Quote:
Daniel B. Martin |
Quote:
Code:
echo Code:
Method of LQ Moderator acid_kewpie as posted Daniel B. Martin |
Quote:
|
Quote:
Daniel B. Martin |
Quote:
Just tried it with Firefox (Iceweasel) and it shows a grey screen....... Try manually adding index.php |
Quote:
|
Quote:
Daniel B. Martin |
Code:
sed -n -e1h -e'2,$'H -e'$x' -e'$s/\n/\&/g' -e'$p' |
All times are GMT -5. The time now is 12:46 AM. |