PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > Remove empty lines using sed, with exceptions
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Remove empty lines using sed, with exceptions

Réponse
 
LinkBack Outils de la discussion
Vieux 24/05/2007, 07h55   #1
Leif
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Remove empty lines using sed, with exceptions


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

  Réponse avec citation
Vieux 24/05/2007, 12h02   #2
Janis
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Remove empty lines using sed, with exceptions

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



  Réponse avec citation
Vieux 24/05/2007, 15h59   #3
Bill Marcum
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Remove empty lines using sed, with exceptions

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.
  Réponse avec citation
Vieux 24/05/2007, 17h02   #4
sil
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Remove empty lines using sed, with exceptions

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 ~]#

  Réponse avec citation
Vieux 24/05/2007, 17h25   #5
Ed Morton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Remove empty lines using sed, with exceptions

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 ^^^^
  Réponse avec citation
Vieux 24/05/2007, 21h48   #6
Michael Tosch
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Remove empty lines using sed, with exceptions

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
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 19h17.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,15957 seconds with 14 queries