one liner to search a file

H

h3r0

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
 
I

Ian Wilson

h3r0 said:
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
 
H

h3r0

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

Ian said:
h3r0 said:
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
 
A

axel

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

Ian said:
h3r0 said:
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
 
M

MrPenguin

Ian Wilson said:
h3r0 said:
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.
Name: e215c03.internal.co.uk
Address: 10.40.10.15


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

^
|
What purpose does the backslash serve?

Axel

to escape the dot. If not the dot is a regex symbol.
 
R

Rick Measham

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

Its an indication that we really do mean a dot here and not an
'any-character'. Inside a character class, a dot is a dot. Anywhere else
and it has a special meaning. Now when it's preceeded by a backslash in
a character class it takes on no special meaning. The backslash is (from
an execution POV) redundant. However when someone else comes along and
reads your code later, they see that you really *did* mean a dot because
you backslashed it.

It's for the programmer, not the interpreter.

Cheers!
Rick Measham
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top