Re: Script to strip lines from files
- From: Etienne Marais <etienne@xxxxxxxxxxxxxxxx;etienne.marais@xxxxxxxxx>
- Date: Fri, 06 Jan 2006 02:09:49 +0200
Christian Hansen wrote:
> Kevin Collins <spamtotrash@xxxxxxxxxxxxxxxxxx> wrote in
> news:slrndrr006.du0.spamtotrash@xxxxxxxxxxxxxxxxx:
>
>> for file in *
>> do
>> lines="$(grep ^IP $file | tail -5)"
>> echo "$lines" > $file
>> done
>>
>
> Thanks. It works, but a parameter I forgot to add was that the files have
> other information also that is not to be touched. The IP lines are at the
> bottom of the file;
>
>
> Name
> Adress
> Phone
> (etc)
> IP 1
> IP 2
> IP 2
>
>
> Now it removes everything but the (5) IP lines.
The following should work if
the IP lines indeed start with
IP and no other lines follows
after the IP lines, what is
what you wanted as I gather.
for file in *
do
# untouched lines, match lines not starting with IP
non_ip_lines="$(grep -v ^IP $file)"
# IP lines, first 5
ip_lines="$(grep -m 5 ^IP $file)"
echo "$non_ip_lines" > $file
echo "$ip_lines" >> $file
done
--
Etienne Marais
Cosmic Link
South Africa
.
- 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
- Re: Script to strip lines from files
- From: Kevin Collins
- Re: Script to strip lines from files
- From: Christian Hansen
- Script to strip lines from files
- Prev by Date: Re: want shell should I learn?
- Next by Date: Re: want shell should I learn?
- Previous by thread: Re: Script to strip lines from files
- Next by thread: Re: Script to strip lines from files
- Index(es):