|
Home > Archive > Unix Shell > December 2007 > insert new line
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| sant527@gmail.com 2007-12-06, 7:36 am |
| I have file with the following content in a single line
<P CLASS=c>tava śiṣyeṇa dhīmatā</P><P
CLASS=t>SYNONYMS</P><P CLASS=t>SYNONYMS</P>
I want to insert a new line at </P>
How to do it using sed command.
| |
| Stephane Chazelas 2007-12-06, 7:36 am |
| On Thu, 6 Dec 2007 00:23:31 -0800 (PST), sant527@gmail.com wrote:
> I have file with the following content in a single line
>
> <P CLASS=c>tava śiṣyeṇa dhīmatā</P><P
> CLASS=t>SYNONYMS</P><P CLASS=t>SYNONYMS</P>
>
> I want to insert a new line at </P>
>
> How to do it using sed command.
Assuming a Bourne-like shell:
sed 's,</P>,&\
,g'
--
Stephane
| |
| Tony Winslow 2007-12-06, 7:36 am |
| Stephane Chazelas wrote:
> On Thu, 6 Dec 2007 00:23:31 -0800 (PST), sant527@gmail.com wrote:
>
> Assuming a Bourne-like shell:
>
> sed 's,</P>,&\
> ,g'
>
sed 's,</p>,&\n,g'
| |
| Stephane Chazelas 2007-12-06, 7:36 am |
| On Thu, 06 Dec 2007 19:32:26 +0800, Tony Winslow wrote:
> Stephane Chazelas wrote:
> sed 's,</p>,&\n,g'
No, that's not standard. The standard way is the way I gave.
\n is only standard in the LHS (in the pattern). According to
the POSIX or Unix standard, the behavior \n in the RHS is
/unspecified/. Some seds may replace with "\n", some with "n"
and some with a newline characters, some may output an error
message...
--
Stephane
| |
| Tony Winslow 2007-12-06, 1:29 pm |
| Stephane Chazelas wrote:
> On Thu, 06 Dec 2007 19:32:26 +0800, Tony Winslow wrote:
>
> No, that's not standard. The standard way is the way I gave.
>
> \n is only standard in the LHS (in the pattern). According to
> the POSIX or Unix standard, the behavior \n in the RHS is
> /unspecified/. Some seds may replace with "\n", some with "n"
> and some with a newline characters, some may output an error
> message...
>
i think you are right. i didn't know about it before. \
Thank you for sharing!
| |
| Michael Tosch 2007-12-06, 1:29 pm |
| Stephane Chazelas wrote:
> On Thu, 6 Dec 2007 00:23:31 -0800 (PST), sant527@gmail.com wrote:
>
> Assuming a Bourne-like shell:
>
> sed 's,</P>,&\
> ,g'
>
If you want to have a new line at *each* </P>.
Only at the 1st </P>
sed 's,</P>,&\
,'
Or at each </P><
sed 's,</P><,</P>\
<,g'
--
Michael Tosch @ hp : com
| |
| sant527@gmail.com 2007-12-07, 7:31 am |
| On Dec 6, 8:42 pm, Michael Tosch <eed...@NO.eed.SPAM.ericsson.PLS.se>
wrote:
> Stephane Chazelas wrote:
>
>
>
>
>
>
> If you want to have a new line at *each* </P>.
>
> Only at the 1st </P>
>
> sed 's,</P>,&\
> ,'
>
> Or at each </P><
>
> sed 's,</P><,</P>\
> <,g'
>
> --
> Michael Tosch @ hp : com
Thank you it solved the problem by
> sed 's,</P>,&\
> ,'
>
> Or at each </P><
>
> sed 's,</P><,</P>\
> <,g'
| |
| sant527@gmail.com 2007-12-07, 7:31 am |
| On Dec 7, 1:53 pm, "sant...@gmail.com" <sant...@gmail.com> wrote:[vbcol=seagreen]
> On Dec 6, 8:42 pm, Michael Tosch <eed...@NO.eed.SPAM.ericsson.PLS.se>
> wrote:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> Thank you it solved the problem by
>
>
>
I am trying to do
bash$ sed 's:<\/*>:&\
:g' 4.htm > cool.htm
its not woking. i am expecting that it should put a line a every where
a end tag is found
| |
|
| On 7 Dez., 10:34, "sant...@gmail.com" <sant...@gmail.com> wrote:
> On Dec 7, 1:53 pm, "sant...@gmail.com" <sant...@gmail.com> wrote:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> I am trying to do
>
> bash$ sed 's:<\/*>:&\
> :g' 4.htm > cool.htm
>
> its not woking. i am expecting that it should put a line a every where
> a end tag is found
You forgot a dot...
sed 's:<\/.*>:&\
:g' 4.htm > cool.htm
Janis
| |
| Bill Marcum 2007-12-07, 7:31 am |
| On 2007-12-07, sant527@gmail.com <sant527@gmail.com> wrote:
>
> I am trying to do
>
>
> bash$ sed 's:<\/*>:&\
>:g' 4.htm > cool.htm
>
> its not woking. i am expecting that it should put a line a every where
> a end tag is found
bash$ sed 's:<\/[^>]*>:&\
:g' 4.htm > cool.htm
| |
| Michael Tosch 2007-12-07, 7:31 am |
| sant527@gmail.com wrote:
> On Dec 7, 1:53 pm, "sant...@gmail.com" <sant...@gmail.com> wrote:
>
> I am trying to do
>
>
> bash$ sed 's:<\/*>:&\
> :g' 4.htm > cool.htm
>
> its not woking. i am expecting that it should put a line a every where
> a end tag is found
* in regular expression means the preceding character ( the / ) can be repeated.
Further, </.*> would be too greedy so you need
sed 's:</[^>]*>:&\
:g' 4.htm > cool.htm
--
Michael Tosch @ hp : com
| |
| sant527@gmail.com 2007-12-07, 7:31 am |
| On Dec 7, 3:21 pm, Michael Tosch <eed...@NO.eed.SPAM.ericsson.PLS.se>
wrote:
> sant...@gmail.com wrote:
>
>
>
>
>
>
> * in regular expression means the preceding character ( the / ) can be repeated.
> Further, </.*> would be too greedy so you need
>
> sed 's:</[^>]*>:&\
> :g' 4.htm > cool.htm
>
> --
> Michael Tosch @ hp : com
Sorry I couldnt get you. * means all thats inbetween to theits
extents.
Why are we using . and what is the meaning of [^>]. Can you explain
the disfferences
| |
| sant527@gmail.com 2007-12-07, 7:31 am |
| On Dec 7, 5:34 pm, "sant...@gmail.com" <sant...@gmail.com> wrote:
> On Dec 7, 3:21 pm, Michael Tosch <eed...@NO.eed.SPAM.ericsson.PLS.se>
> wrote:
>
>
>
>
>
>
>
>
>
>
>
>
> Sorry I couldnt get you. * means all thats inbetween to theits
> extents.
>
> Why are we using . and what is the meaning of [^>]. Can you explain
> the disfferences
in the below single line
<P CLASS=c>tava śiṣyeṇa dhīmatā</P><P
CLASS=t>SYNONYMS</P><P CLASS=t>SYNONYMS</P>
I want to insert a new line before <P> or every occurence of tag.
How to do it using sed command.
|
|
|
|
|