|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
How can I remove all newlines with exceptions? This is a part of my text. I would like to remove all newlines. But newlines should be kept if the next line starts with '/*@' or if the current line starts with '/*@'. ----------- e.stopPropagation(); e.preventDefault(); /*@cc_on /*@if (@_win32) e.cancelBubble=true; e.returnValue=false; /*@end ----------- what I want: ----------- e.stopPropagation();e.preventDefault(); /*@cc_on /*@if (@_win32) e.cancelBubble=true;e.returnValue=false; /*@end ----------- I'm guessing this would need two steps. 1) remove all newlines 2) insert newlines Could someone me figure out what sed command I should use for 2)? #!/bin/sh cat a.js b.js c.js > /tmp/combined.js cat /tmp/combined.js | sed -e 'N;s/\n//;P;D;' | sed -e "????" > out.js The first command I found at wikipedia http://en.wikipedia.org/wiki/Sed - I don't think it's working though. Any suggestions? Leif |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On 24 Mai, 08:55, Leif <leifwess...@hotmail.com> wrote:
> How can I remove all newlines with exceptions? > > This is a part of my text. I would like to remove all newlines. But > newlines should be kept if the next line starts with '/*@' or if the > current line starts with '/*@'. > > ----------- > e.stopPropagation(); > e.preventDefault(); > > /*@cc_on > > /*@if (@_win32) > > e.cancelBubble=true; > e.returnValue=false; > > /*@end > ----------- > > what I want: > > ----------- > e.stopPropagation();e.preventDefault(); > /*@cc_on > /*@if (@_win32) > e.cancelBubble=true;e.returnValue=false; > /*@end > ----------- > > I'm guessing this would need two steps. 1) remove all newlines 2) > insert newlines > Could someone me figure out what sed command I should use for 2)? > > #!/bin/sh > cat a.js b.js c.js > /tmp/combined.js > cat /tmp/combined.js | sed -e 'N;s/\n//;P;D;' | sed -e "????" > out.js > > The first command I found at wikipediahttp://en.wikipedia.org/wiki/Sed > - I don't think it's working though. > > Any suggestions? One possibility... awk ' !NF {next} /^\/\*@/ {if(t)print ""; t=0; print; next} {t=1; printf("%s",$0)} ' Janis > > Leif |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
On 23 May 2007 23:55:22 -0700, Leif
<leifwessman@hotmail.com> wrote: > > > > How can I remove all newlines with exceptions? > > This is a part of my text. I would like to remove all newlines. But > newlines should be kept if the next line starts with '/*@' or if the > current line starts with '/*@'. > > ----------- > e.stopPropagation(); > e.preventDefault(); > > /*@cc_on > > > /*@if (@_win32) > > e.cancelBubble=true; > e.returnValue=false; > > /*@end > ----------- > > what I want: > > ----------- > e.stopPropagation();e.preventDefault(); > /*@cc_on > /*@if (@_win32) > e.cancelBubble=true;e.returnValue=false; > /*@end > ----------- > > I'm guessing this would need two steps. 1) remove all newlines 2) > insert newlines > Could someone me figure out what sed command I should use for 2)? > > #!/bin/sh > cat a.js b.js c.js > /tmp/combined.js > cat /tmp/combined.js | sed -e 'N;s/\n//;P;D;' | sed -e "????" > out.js > cat a.js b.js c.js | tr -d '\n' | sed -e 's|/\*@| /*@' >out.js -- The discerning person is always at a disadvantage. |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On May 24, 2:55 am, Leif <leifwess...@hotmail.com> wrote:
> How can I remove all newlines with exceptions? > > This is a part of my text. I would like to remove all newlines. But > newlines should be kept if the next line starts with '/*@' or if the > current line starts with '/*@'. > > ----------- > e.stopPropagation(); > e.preventDefault(); > > /*@cc_on > > /*@if (@_win32) > > e.cancelBubble=true; > e.returnValue=false; > > /*@end > ----------- > > what I want: > > ----------- > e.stopPropagation();e.preventDefault(); > /*@cc_on > /*@if (@_win32) > e.cancelBubble=true;e.returnValue=false; > /*@end > ----------- > > I'm guessing this would need two steps. 1) remove all newlines 2) > insert newlines > Could someone me figure out what sed command I should use for 2)? > > #!/bin/sh > cat a.js b.js c.js > /tmp/combined.js > cat /tmp/combined.js | sed -e 'N;s/\n//;P;D;' | sed -e "????" > out.js > > The first command I found at wikipediahttp://en.wikipedia.org/wiki/Sed > - I don't think it's working though. > > Any suggestions? > > Leif sed 'N;N;s/\n//g' /tmp/combined.js [root@linuxbox ~]# cat test e.stopPropagation(); e.preventDefault(); /*@cc_on /*@if (@_win32) e.cancelBubble=true; e.returnValue=false; /*@end [root@linuxbox ~]# sed 'N;N;s/\n//g' test e.stopPropagation();e.preventDefault(); /*@cc_on /*@if (@_win32)e.cancelBubble=true; e.returnValue=false;/*@end [root@linuxbox ~]# |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
sil wrote:
> On May 24, 2:55 am, Leif <leifwess...@hotmail.com> wrote: > >>How can I remove all newlines with exceptions? >> >>This is a part of my text. I would like to remove all newlines. But >>newlines should be kept if the next line starts with '/*@' or if the >>current line starts with '/*@'. >> >>----------- >>e.stopPropagation(); >>e.preventDefault(); >> >>/*@cc_on >> >>/*@if (@_win32) >> >>e.cancelBubble=true; >>e.returnValue=false; >> >>/*@end >>----------- >> >>what I want: >> >>----------- >>e.stopPropagation();e.preventDefault(); >>/*@cc_on >>/*@if (@_win32) >>e.cancelBubble=true;e.returnValue=false; >>/*@end <snip> > [root@linuxbox ~]# sed 'N;N;s/\n//g' test > e.stopPropagation();e.preventDefault(); > /*@cc_on > /*@if (@_win32)e.cancelBubble=true; > e.returnValue=false;/*@end Ahem ^^^^ |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
Leif wrote:
> How can I remove all newlines with exceptions? > > This is a part of my text. I would like to remove all newlines. But > newlines should be kept if the next line starts with '/*@' or if the > current line starts with '/*@'. > > ----------- > e.stopPropagation(); > e.preventDefault(); > > /*@cc_on > > > /*@if (@_win32) > > e.cancelBubble=true; > e.returnValue=false; > > /*@end > ----------- > > what I want: > > ----------- > e.stopPropagation();e.preventDefault(); > /*@cc_on > /*@if (@_win32) > e.cancelBubble=true;e.returnValue=false; > /*@end > ----------- > > I'm guessing this would need two steps. 1) remove all newlines 2) > insert newlines > Could someone me figure out what sed command I should use for 2)? > > #!/bin/sh > cat a.js b.js c.js > /tmp/combined.js > cat /tmp/combined.js | sed -e 'N;s/\n//;P;D;' | sed -e "????" > out.js > > The first command I found at wikipedia http://en.wikipedia.org/wiki/Sed > - I don't think it's working though. > > Any suggestions? > > Leif > sed 'N;=' shows it bundles the input in pairs - no good. If you don't mind one empty line between two /*@ statements: perl -pe 'if (/^\/\*\@/) {print "\n"} else {chop}' -- Michael Tosch @ hp : com |
|
![]() |
| Outils de la discussion | |
|
|