Re: Script to strip lines from files



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
.



Relevant Pages

  • Re: 102" whip
    ... >makes a Rat Shack whip such a bad design? ... I don't care what makes it bad. ... Do the test then you can hypothesize ... Prev by Date: ...
    (rec.radio.cb)
  • Re: Cyclist killers in local paper.
    ... So that contradicts your first statement. ... Either applies and the word is valid, or your assertion that, "It ... Care to try again, this time using a consistent form logic throughout ... Prev by Date: ...
    (uk.rec.cycling)
  • RE: address bar
    ... > When I type an web address in the addres bar, it gives me an arrow message. ... > Then I have to type in http:\\web adress to get to the sit I need to get to. ... > I use to type in the address and press Ctrl + Enter. ... Prev by Date: ...
    (microsoft.public.windows.inetexplorer.ie6.setup)
  • Re: To MSCE or not to MSCE
    ... Cisco or a Master's degree. ... > care to share their .02 as to what and why? ... What are you really passionate about? ... Prev by Date: ...
    (microsoft.public.cert.exam.mcse)
  • Using combo boxes to fill in other bound controls not working..
    ... other tables and I am not able to get the tables to display with the valid ... Take care, ... Smriti ... Prev by Date: ...
    (comp.databases.ms-access)