Re: Script to strip lines from files



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
.



Relevant Pages

  • Re: schedule a task to run a korn shell script
    ... This is UNIX CHRON jobs, or CRON jobs? ... If your script expects to be in a certain directory, ...
    (comp.unix.questions)
  • Re: .Net Equivilant for sqlcmd or osql
    ... applications like SQL Management Studio work. ... Also, you do not have to strip the comments, it works just fine, ... Read EACH line into a string buffer. ... Read your script file and split it on the GO ...
    (microsoft.public.dotnet.languages.csharp)
  • Script to strip lines from files
    ... I would apreciate som help making a script that be run from cron and can ... to strip the first instance of "IP" until the file only contains five. ...
    (comp.unix.shell)
  • [OT] FOAK: Regexp experts.
    ... I'm trying to set up a script to strip out URL's from the body of a ... Cab:^) - argue's like a girl ... GSX 1400 ...
    (uk.rec.motorcycles)
  • WMI is not seeing specific services on some servers
    ... The script runs well; however, on a few servers, even though both ... WMI reports PatchLink as missing. ... Dim x, strIP, varSubNet ...
    (microsoft.public.scripting.vbscript)