For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > June 2005 > one liner to search a file









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author one liner to search a file
h3r0

2005-06-09, 3:57 pm

hi

i need to search a file which contains the data below and extract the
machine name only in this case 'e215c03' and overwrite the file.

many thanks for your help.


Name: e215c03.internal.co.uk
Address: 10.40.10.15

Ian Wilson

2005-06-09, 3:57 pm

h3r0 wrote:
> hi
>
> i need to search a file which contains the data below and extract the
> machine name only in this case 'e215c03' and overwrite the file.
>
> many thanks for your help.
>
>
> Name: e215c03.internal.co.uk
> Address: 10.40.10.15
>



perl -n -i -e '/^Name:\s+([^\.]+)/ && print $1' filename
h3r0

2005-06-09, 3:57 pm

it wanted a backup file name, works great your a star! :)
thanks for your fast responses.

Ian Wilson wrote:
> h3r0 wrote:
>
>
> perl -n -i -e '/^Name:\s+([^\.]+)/ && print $1' filename


axel@white-eagle.invalid.uk

2005-06-09, 8:57 pm

h3r0 <h3r0@my-deja.com> wrote:
> it wanted a backup file name, works great your a star! :)
> thanks for your fast responses.
>
> Ian Wilson wrote:
>

axel@white-eagle.invalid.uk

2005-06-09, 8:57 pm

Ian Wilson <scobloke2@infotop.co.uk> wrote:
> h3r0 wrote:
[color=darkred]
[color=darkred]
> perl -n -i -e '/^Name:\s+([^\.]+)/ && print $1' filename

^
|
What purpose does the backslash serve?

Axel
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com