Re: Script to strip lines from files
- From: Kevin Collins <spamtotrash@xxxxxxxxxxxxxxxxxx>
- Date: Thu, 05 Jan 2006 20:22:30 GMT
In article <Xns9742C1E2EF074idontwantemail@xxxxxxxxxxxxxxx>, Christian Hansen
wrote:
> I would apreciate som help making a script that be run from cron and can
> strip lines from files in the work dir.
>
> I want the files to only be able to have a certain number of lines (say
> five) that start with "IP" . If the file has more I would like the script
> to strip the first instance of "IP" until the file only contains five.
Quick and dirty:
for file in *
do
lines="$(grep ^IP $file | tail -5)"
echo "$lines" > $file
done
That will work in ksh or bash (probably any POSIX shell)...
Kevin
--
Unix Guy Consulting, LLC
Unix and Linux Automation, Shell, Perl and CGI scripting
http://www.unix-guy.com
.
- Follow-Ups:
- Re: Script to strip lines from files
- From: Christian Hansen
- Re: Script to strip lines from files
- References:
- Script to strip lines from files
- From: Christian Hansen
- Script to strip lines from files
- Prev by Date: Re: how to edit only one paragraph
- Next by Date: Re: Script to strip lines from files
- Previous by thread: Script to strip lines from files
- Next by thread: Re: Script to strip lines from files
- Index(es):
Relevant Pages
|