Re: some kind of binary sed(1) command

2012-02-02 Thread Matthias Apitz
El día Thursday, February 02, 2012 a las 01:51:56AM -0600, Robert Bonomi 
escribió:

  From owner-freebsd-questi...@freebsd.org  Thu Feb  2 00:27:33 2012
  Date: Thu, 2 Feb 2012 07:22:36 +0100
  From: Matthias Apitz g...@unixarea.de
  To: freebsd-questions@freebsd.org
  Subject: some kind of binary sed(1) command
 
 
  Hello,
 
  I have a normal ASCII file wich has in some places two lines of '*',
  separated by an empty line, i.e.
 
  \n
  *\n
  \n
  *\n
  \n
 
  and I want to substitute the \n between the star lines by \f; the
  'binary' sed command would just be 
 
  s/*\n\n*/*\n\f*/
 
  which ofc does not work with sed(1) because it is line oriented;
  I could write something in perl, C, awk or whatever language, but I
  would prefer to do it with the normal commands... any ideas?
 
 lightbulb mode=on
 Use sed.  
 /lightbulb
 
 *GRIN*

Thanks, but the attached script (based on your content and saved to a
script file) just gives:

$ sh sed
sed: 5:  t l
   :l
 ...: invalid command code /


Leaving your original mail as well here; Thanks again

matthias

 
 
 
 
 
 As follows:
 
   sed -e ' t l
:l
/^[*]+$/ {
N
!/\n$/ { 
P
s/^.*\n//
t l
}
/\n$/ {
N
!/\n\n[*]*$/ {
P
s/^.*\n//
P
s/^.*\n//
t l
}
/\n\n[*]*$/ s/\n\n/\n\f/
}  
}'  
 
 Note: how this incantation works is left as an excercise for the student. 
   Careful perusal of the FM will provide enlightenment.
 
 Caveat: this will convert:
{stars}
{blank}
{stars}
{blank}
{stars}
 
 to;
{stars}
{formfeed}
{stars}
{blank}
{stars}
 
 not:
{stars}
{formfeed}
{stars}
{formfeed}
{stars}
 ___
 freebsd-questions@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/freebsd-questions
 To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org

-- 
Matthias Apitz
t +49-89-61308 351 - f +49-89-61308 399 - m +49-170-4527211
e g...@unixarea.de - w http://www.unixarea.de/
¡Ya basta! ¡Imperialistas occidentales, quitad las manos de Libia!
There's an end of it! Imperialists occidentals, hands off Libya!
Schluss jetzt endlich! Imperialisten des Westens, Haende weg von Libyen!
#!/bin/sh

  sed -e ' t l
   :l
   /^[*]+$/ {
   N
   !/\n$/ { 
   P
   s/^.*\n//
   t l
   }
   /\n$/ {
   N
   !/\n\n[*]*$/ {
   P
   s/^.*\n//
   P
   s/^.*\n//
   t l
   }
   /\n\n[*]*$/ s/\n\n/\n\f/
   }  
   }'  
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org

Re: some kind of binary sed(1) command

2012-02-02 Thread Robert Bonomi

 From: Matthias Apitz g...@unixarea.de

 El dia Thursday, February 02, 2012 a las 01:51:56AM -0600, Robert Bonomi 
 escribio:

 Thanks, but the attached script (based on your content and saved to a
 script file) just gives:

*sigh*  the code worked wih gnu sed.

BSD sed is a whole lot more finicky with regard to whitespace.  And, it 
appears that  I've got some bug reports to file. 

Anyway, this is tested on FBSD 7.2:
copy _exactly_, making sure there is no trailing white-space on any line.
Then substitute an actual formfeed char for the {CTL-L}.
FreeBSD sed does not recognize either '\n' or '\f' in the substitution
string -- it strips the '\' and outputs the printable character.  *sigh* 

#!/bin/sh

sed  -e '
:l
/^[*][*]*$/ N
/\n..*$/ P
/\n..*$/ {
s/^.*\n//
b l
}
/\n$/ N
/\n\n[^*][^*]*$/ {
P
s/^.*\n// 
P
s/^.*\n//
b l
}
/\n\n[*]*$/ s/\n\n/\
{CTL-L}/'

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: some kind of binary sed(1) command

2012-02-02 Thread Nikos Vassiliadis

On 2/2/2012 8:22 AM, Matthias Apitz wrote:


Hello,

I have a normal ASCII file wich has in some places two lines of '*',
separated by an empty line, i.e.

\n
*\n
\n
*\n
\n

and I want to substitute the \n between the star lines by \f; the
'binary' sed command would just be

s/*\n\n*/*\n\f*/

which ofc does not work with sed(1) because it is line oriented;
I could write something in perl, C, awk or whatever language, but I
would prefer to do it with the normal commands... any ideas?

Thanks

matthias


Perhaps, something like this:

raidmadi% sed '/\*\*\*\*/{ N;N;s/\(\*\*\*\*\n\)\(\n\)\(\*\*\*\*\)/\1\\f\
\3/; }; '




\f


foo


foo



Keep in mind that I am using zsh which allows you to write multi-line
commands.

HTH, Nikos
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: some kind of binary sed(1) command

2012-02-01 Thread Robert Bonomi
 From owner-freebsd-questi...@freebsd.org  Thu Feb  2 00:27:33 2012
 Date: Thu, 2 Feb 2012 07:22:36 +0100
 From: Matthias Apitz g...@unixarea.de
 To: freebsd-questions@freebsd.org
 Subject: some kind of binary sed(1) command


 Hello,

 I have a normal ASCII file wich has in some places two lines of '*',
 separated by an empty line, i.e.

 \n
 *\n
 \n
 *\n
 \n

 and I want to substitute the \n between the star lines by \f; the
 'binary' sed command would just be 

 s/*\n\n*/*\n\f*/

 which ofc does not work with sed(1) because it is line oriented;
 I could write something in perl, C, awk or whatever language, but I
 would prefer to do it with the normal commands... any ideas?

lightbulb mode=on
Use sed.  
/lightbulb

*GRIN*





As follows:

  sed -e ' t l
   :l
   /^[*]+$/ {
   N
   !/\n$/ { 
   P
   s/^.*\n//
   t l
   }
   /\n$/ {
   N
   !/\n\n[*]*$/ {
   P
   s/^.*\n//
   P
   s/^.*\n//
   t l
   }
   /\n\n[*]*$/ s/\n\n/\n\f/
   }  
   }'  

Note: how this incantation works is left as an excercise for the student. 
  Careful perusal of the FM will provide enlightenment.

Caveat: this will convert:
   {stars}
   {blank}
   {stars}
   {blank}
   {stars}

to;
   {stars}
   {formfeed}
   {stars}
   {blank}
   {stars}

not:
   {stars}
   {formfeed}
   {stars}
   {formfeed}
   {stars}
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org