need help on unix
Glenn Host
ghost at nrl-cmf.UUCP
Wed Jun 12 00:47:13 AEST 1991
In article <6420 at ns-mx.uiowa.edu> dsiebert at icaen.uiowa.edu (Doug Siebert) writes:
>In article <1991Jun11.010644.22356 at unixg.ubc.ca> wangf at unixg.ubc.ca (Frank Wang) writes:
>>Is that possible to delete some lines from a file (the file is so large that
>>it's impossible to use any editor) without evoking any editors?
>>
>>Thanx in advance.
>
>Try checking "man sed"
Actually it is much simplier
Just split the file and edit it in pieces
here is a script which handles it:
#!/bin/sh
#
# Edit very large file
#
# Copywrite 1991 Glenn Host, NRL
# You are free to redistribute or modify this
# I do not grant rights to sell it but I probably can't stop you if you do
# Of course since I work for the government, they probably can :-)
#
# This script splits a file into pieces so the pieces can be editted separately
#
# The -q option specifies that nuincance error messages and usage lines
# are not to be displayed.
#
# The -l lines specifies the number of lines to solit file into
# This should be smaller than the limit of your editor.
#
# The EDITOR variable specifies the editor to use for editing the
# split files. It needs to handle multiple files
#
USAGE="usage: $0 [-q] [-l lines] file [file ..]"
ID=$$.
editor=${EDITOR-vi}
#
# pecho is a portable echo that works on all systems
# inquire for source if you are interested in it
# It allows \c, etc to work on BSD-style systems
#
pecho=${PECHO-echo}
set -- `getopt ql: $*`
q=0 # quiet: display nuiciance warning messages
error=0 # error flag for non-fatal errors (display usage once)
lines=1000 # same as default on split command
for opt in $*
do
case $opt in
-l) lines=$2;;
-q) q=1;;
--) shift; break;;
-?) echo "$USAGE" ; exit 1;;
esac
shift
done
files="$*"
if [ $# -eq 0 ]
then
echo "No files supplied"
echo $USAGE
exit 2
fi
for file in $files
do
if [ ! -f $file ] ; then
if [ $q -eq 0 ] ; then echo "File $file does not exist" ; fi
error=1
elif [ ! -w $file ] ; then
if [ $q -eq 0 ] ; then echo "Can not write to $file" ; fi
error=1
else
split -$lines $file $ID
$EDITOR ${ID}*
$pecho "Recombine into original file \"$file\"? ([n]o/yes/abort) \c"
read combine
case "$combine" in
[yY]*)
cat ${ID}* > $file && rm ${ID}*
status=$?
if [ $status -ne 0 ] ; then
echo "$0: Combine not performed - temporary files remain!"
exit $status
else
if [ $q -eq 0 ] ; then echo "Combined into $file successfully" ; fi
fi
;;
[Aa]*)
echo "$0: Combine not performed - temporary files not removed"
exit 0;;
*)
echo "$0: Combine not performed - temporary files removed"
rm ${ID}*;;
esac
fi
done
if [ $q -eq 0 -a $error -eq 1 ] ; then echo $USAGE; fi
--
Glenn Host - Senior Systems Analyst (ghost at ra.nrl.navy.mil)
NRL Code 5800, 4555 Overlook Ave.; Washington, DC 20375 (202) 767-2046
12307 Tigers Eye Court ; Reston, VA 22091 (703) 620-1141
Don't pay attention to header - my news/mail handler is looking for attention
More information about the Comp.unix.shell
mailing list