Stephen_Reilly at dell.com wrote:
> Come to think of it...
> sed /begin/,/end/d filename will do just that...
>> steve
This reminds me that I used this when I was messing
with patchfs for midnight commander. For those who
don't know it's REALLY easy to create virtual filesystems
for midnight commander. Ones that exist already are
ftp/tar/rpm/deb/.. and I created this one for browsing
into patch files (in unified format):
####### snip ########
#! /bin/sh
export LC_ALL=C
patchfs_list ()
{
date=`date +"%b %d %H:%M"`
perm="-r--r--r--"
uid=00000000
gid=00000000
size=00000000
nlink=" 1"
echo "$perm $nlink $uid $gid $size $date SUMMARY"
$cat $1 |
sed -n "s/^+++ \([^ ]*\).*/$perm $nlink $uid $gid $size $date \1/gp"
}
patchfs_copyout ()
{
if [ "$2" = SUMMARY ]; then # list of all affected files
if diffstat -V >/dev/null 2>&1; then
$cat $1 | diffstat 2>/dev/null > $3
else
sed -n "s/^+++ \([^ ]*\).*/\1/gp" > $3
fi
exit 0
fi
fn=`echo $2 | sed 's|/|\\\/|g'` # escape '/' in filename
$cat $1 |
sed -e '/^diff /d' |
sed -ne "/^+++ .*$fn/,/^--- /{
/^--- /d
p
}" > $3
}
type=`file $2`
case $type in
*bzip*) cat="bzip2 -dc" ;;
*gzip*) cat="gzip -dc" ;;
*text*) cat="cat" ;;
*) exit 1
esac
umask 077
case "$1" in
list) patchfs_list $2; exit 0;;
copyout) patchfs_copyout $2 $3 $4; exit 0;;
run) exit 0;;
esac
exit 1
####### snip ########
You need to copy this to or overwrite /usr/lib/mc/extfs/patchfs,
and for all users to be able to use this automatically you
will need to edit /usr/lib/mc/mc.ext and before ### Archives ### add:
# Patches
regex/\.(patch|diff)\.*(gz|bz2)*$
Open=%cd %p#patchfs
you will also need to do the same in your ~/.mc/ini file if it exits.
In summary all you need to do when this is set up is to browse to
a directory containing (compressed) patch files (*.diff or *.patch),
and hit return on the file, and you can view bits/stats of the patch
with F3.
It really is worth investing the 15 minutes required to learn mc.
It is so powerful, and nicely integrates with the unix environment
as illustrated above.
Padraig.
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!