sed problem
am 04.03.2004 18:08:06 von Jens Knoell
Oke... sed-hell again.
Case: I have a file that has lines separated by pipe chars. I need to split
it back into a line-by-line file. So I tried this (the ^M has been entered
by pushing Ctrl+V, Enter):
echo "This|should|be|on|separate|lines" | sed -e "s/|/^M/g"
The result:
linesate
I'm sure I'm missing something, but hours of googling didn't get me
anywhere. Any ideas?
Thanks
Jens
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: sed problem
am 04.03.2004 18:17:52 von Glynn Clements
Jens Knoell wrote:
> Oke... sed-hell again.
>
> Case: I have a file that has lines separated by pipe chars. I need to split
> it back into a line-by-line file. So I tried this (the ^M has been entered
> by pushing Ctrl+V, Enter):
> echo "This|should|be|on|separate|lines" | sed -e "s/|/^M/g"
>
> The result:
> linesate
>
> I'm sure I'm missing something, but hours of googling didn't get me
> anywhere. Any ideas?
The Unix line seperator is LF (ASCII 10, ^J), not CR (ASCII 13, ^M).
Sending a lone CR to a terminal will simply move the cursor to the
begnning of the line, so you are seeing all of the lines printed on
top of each other ("separate" is the longest line, so it overwrites
everything; "lines" then overwrites the first 5 characters of
"separate", leaving "linesate" on the terminal).
What you actually want is:
echo "This|should|be|on|separate|lines" | sed -e 's/|/\^J/g'
where the ^J is entered using Ctrl-V Ctrl-J. Note the use of single
quotes rather than double quotes, and the backslash before the ^J.
Both of these are necessary to prevent the LF being interpreted by
either the shell or sed.
--
Glynn Clements
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: sed problem
am 04.03.2004 18:25:22 von Matt Hemingway
I'm probably wrong, but isn't ^M the DOS newline character thingy, which you see when opening Windows/DOS files in *nix? Wouldn't \n be right for *nix?
-Matt
On Thu, 4 Mar 2004 10:08:06 -0700
"Jens Knoell" wrote:
> Oke... sed-hell again.
>
> Case: I have a file that has lines separated by pipe chars. I need to split
> it back into a line-by-line file. So I tried this (the ^M has been entered
> by pushing Ctrl+V, Enter):
> echo "This|should|be|on|separate|lines" | sed -e "s/|/^M/g"
>
> The result:
> linesate
>
> I'm sure I'm missing something, but hours of googling didn't get me
> anywhere. Any ideas?
>
> Thanks
> Jens
>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-admin" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: sed problem
am 05.03.2004 08:42:46 von csoler
Hi Jens,
----- Mensaje Original -----
De: "Jens Knoell"
=46echa: Jueves, Marzo 4, 2004 6:08 pm
Asunto: sed problem
> Oke... sed-hell again.
>=20
> Case: I have a file that has lines separated by pipe chars. I need=20
> to split
> it back into a line-by-line file. So I tried this (the ^M has been=20
> enteredby pushing Ctrl+V, Enter):
> echo "This|should|be|on|separate|lines" | sed -e "s/|/^M/g"
>=20
> The result:
> linesate
>=20
> I'm sure I'm missing something, but hours of googling didn't get me
> anywhere. Any ideas?
I think awk fits better for this task, IMHO of course :-)
csoler@gudu$ echo "This|should|be|on|separate|lines" | awk -F"|" '{for=20
(i=3D1; i<=3D NF; i++) print $i}'
This
should
be
on
separate
lines
I hope this helps you...
Cheers,
C=E9sar
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" =
in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: sed problem
am 05.03.2004 09:55:23 von urgrue
I think "tr" does this even easier (IMHO of course ;)
hal:~ # echo "This|should|be|on|separate|lines" | tr \| \\n
This
should
be
on
separate
lines
> I think awk fits better for this task, IMHO of course :-)
>=20
> csoler@gudu$ echo "This|should|be|on|separate|lines" | awk -F"|" '{fo=
r
>=20
> (i=3D1; i<=3D NF; i++) print $i}'
> This
> should
> be
> on
> separate
> lines
>=20
> I hope this helps you...
>=20
> Cheers,
> C=E9sar
>=20
> -
> To unsubscribe from this list: send the line "unsubscribe linux-
> admin"
> in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>=20
>=20
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" =
in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: sed problem
am 09.03.2004 09:46:03 von Stephen Samuel
sed 's/|/\n/g'
(( I like using single quotes, because you're less likely to get
characters like '\' and '$' eaten by the shell ))
csoler@euskalnet.net wrote:
> Hi Jens,
>=20
> ----- Mensaje Original -----
> De: "Jens Knoell"
> Fecha: Jueves, Marzo 4, 2004 6:08 pm
> Asunto: sed problem
>=20
>=20
>>Oke... sed-hell again.
>>
>>Case: I have a file that has lines separated by pipe chars. I need=20
>>to split
>>it back into a line-by-line file. So I tried this (the ^M has been=20
>>enteredby pushing Ctrl+V, Enter):
>>echo "This|should|be|on|separate|lines" | sed -e "s/|/^M/g"
>>
>>The result:
>>linesate
>>
>>I'm sure I'm missing something, but hours of googling didn't get me
>>anywhere. Any ideas?
>=20
>=20
> I think awk fits better for this task, IMHO of course :-)
>=20
> csoler@gudu$ echo "This|should|be|on|separate|lines" | awk -F"|" '{fo=
r=20
> (i=3D1; i<=3D NF; i++) print $i}'
> This
> should
> be
> on
> separate
> lines
>=20
> I hope this helps you...
>=20
> Cheers,
> C=E9sar
>=20
> -
> To unsubscribe from this list: send the line "unsubscribe linux-admin=
" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
--=20
Stephen Samuel +1(604)876-0426 samuel@bcgreen.com
http://www.bcgreen.com/~samuel/
Powerful committed communication. Transformation touching
the jewel within each person and bringing it to light.
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" =
in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html