Re: Script to strip lines from files
- From: Christian Hansen <i.dont@xxxxxxxxxxx>
- Date: Fri, 06 Jan 2006 18:06:36 -0600
Etienne Marais <etienne@xxxxxxxxxxxxxxxx;etienne.marais@xxxxxxxxx> wrote
in news:dpkcah$gbp$1@xxxxxxxxxxxxxxxxxx:
> 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
>
>
Well it works. And that's all I care about. Thanks alot Etienne, and you
all for putting in an effort to help me.
CH
.
- 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
- Re: Script to strip lines from files
- From: Etienne Marais
- Script to strip lines from files
- Prev by Date: Re: Regualar Expression Theory
- 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):
Relevant Pages
|