* Re: sed problem
@ 2004-03-05 7:42 csoler
2004-03-05 8:55 ` urgrue
2004-03-09 8:46 ` Stephen Samuel
0 siblings, 2 replies; 6+ messages in thread
From: csoler @ 2004-03-05 7:42 UTC (permalink / raw)
To: Jens Knoell; +Cc: Linux Admin
Hi Jens,
----- Mensaje Original -----
De: "Jens Knoell" <jens@surefoot.com>
Fecha: Jueves, Marzo 4, 2004 6:08 pm
Asunto: sed problem
> 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
> 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?
I think awk fits better for this task, IMHO of course :-)
csoler@gudu$ echo "This|should|be|on|separate|lines" | awk -F"|" '{for
(i=1; i<= NF; i++) print $i}'
This
should
be
on
separate
lines
I hope this helps you...
Cheers,
César
-
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
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: sed problem
2004-03-05 7:42 sed problem csoler
@ 2004-03-05 8:55 ` urgrue
2004-03-09 8:46 ` Stephen Samuel
1 sibling, 0 replies; 6+ messages in thread
From: urgrue @ 2004-03-05 8:55 UTC (permalink / raw)
To: admin
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 :-)
>
> csoler@gudu$ echo "This|should|be|on|separate|lines" | awk -F"|" '{for
>
> (i=1; i<= NF; i++) print $i}'
> This
> should
> be
> on
> separate
> lines
>
> I hope this helps you...
>
> Cheers,
> César
>
> -
> 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
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: sed problem
2004-03-05 7:42 sed problem csoler
2004-03-05 8:55 ` urgrue
@ 2004-03-09 8:46 ` Stephen Samuel
1 sibling, 0 replies; 6+ messages in thread
From: Stephen Samuel @ 2004-03-09 8:46 UTC (permalink / raw)
To: csoler; +Cc: Jens Knoell, Linux Admin
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,
>
> ----- Mensaje Original -----
> De: "Jens Knoell" <jens@surefoot.com>
> Fecha: Jueves, Marzo 4, 2004 6:08 pm
> Asunto: sed problem
>
>
>>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
>>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?
>
>
> I think awk fits better for this task, IMHO of course :-)
>
> csoler@gudu$ echo "This|should|be|on|separate|lines" | awk -F"|" '{for
> (i=1; i<= NF; i++) print $i}'
> This
> should
> be
> on
> separate
> lines
>
> I hope this helps you...
>
> Cheers,
> César
>
> -
> 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
--
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* sed problem
@ 2004-03-04 17:08 Jens Knoell
2004-03-04 17:17 ` Glynn Clements
2004-03-04 17:25 ` Matt Hemingway
0 siblings, 2 replies; 6+ messages in thread
From: Jens Knoell @ 2004-03-04 17:08 UTC (permalink / raw)
To: Linux Admin
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: sed problem
2004-03-04 17:08 Jens Knoell
@ 2004-03-04 17:17 ` Glynn Clements
2004-03-04 17:25 ` Matt Hemingway
1 sibling, 0 replies; 6+ messages in thread
From: Glynn Clements @ 2004-03-04 17:17 UTC (permalink / raw)
To: Jens Knoell; +Cc: Linux Admin
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 <glynn.clements@virgin.net>
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: sed problem
2004-03-04 17:08 Jens Knoell
2004-03-04 17:17 ` Glynn Clements
@ 2004-03-04 17:25 ` Matt Hemingway
1 sibling, 0 replies; 6+ messages in thread
From: Matt Hemingway @ 2004-03-04 17:25 UTC (permalink / raw)
To: Jens Knoell; +Cc: Linux Admin
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" <jens@surefoot.com> 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
>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2004-03-09 8:46 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-03-05 7:42 sed problem csoler
2004-03-05 8:55 ` urgrue
2004-03-09 8:46 ` Stephen Samuel
-- strict thread matches above, loose matches on Subject: below --
2004-03-04 17:08 Jens Knoell
2004-03-04 17:17 ` Glynn Clements
2004-03-04 17:25 ` Matt Hemingway
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).