On Thursday 26 April 2007 08:51, Zhang Weiwu wrote: > On Thu, 2007-04-26 at 11:18 +0800, Zhang Weiwu wrote: [snip] > > I have a data file formatted like this each block of data consist of > > several lines; blocks are separated by empty lines like this > > > > This is a > > block > > of data > > with lines > > > > and another block > > of > > data > > > > The task is to move the last line of each block to the first line of the > > block. So the processed data look like this: > > > > with lines > > This is a > > block > > of data > > > > data > > and other block > > of [snip] I would use Perl, which can read in a paragraph at a time. Assuming you don't mind having multiple blank lines in the input replaced by a single blank line, this Perl commandline will do what you want:
perl -l -00 -pe 's/(.*)^(.*)$/$2\n$1/ms' datafile Read perldoc perlrun for the flags, and perldoc perlre to understand the regex (in particular the m and s modifiers). Jonathan _______________________________________________ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"