LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-17-2008, 02:28 AM   #1
wondergirl
LQ Newbie
 
Registered: Feb 2008
Posts: 18

Rep: Reputation: 0
Perl pattern matching - greedy


Hi all,
I have a problem at the moment that has stumped me for a couple of days now...

I have a file containing public key for ssh, called authorized_keys2, containing :

ssh-dss xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxbbbbbbbbbbbbbxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxx== root@servername

I want to create a perl one liner so that it will match only the 'root@servername' part of the file and returns it to me. Is this possible? Appreciate your help. I've tried to do it with awk and sed with no success.....
 
Old 06-17-2008, 02:31 AM   #2
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
assuming the data you provided goes line by line, the root@servername portion is the last field
Code:
awk '{print $NF}' authorization_file
 
Old 06-17-2008, 04:32 PM   #3
Su-Shee
Member
 
Registered: Sep 2007
Location: Berlin
Distribution: Slackware
Posts: 509

Rep: Reputation: 41
perl -nae '@foo = split; print $foo[2];' the_file
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
can't get non-greedy matching to work in sed lumix Linux - Newbie 3 05-05-2008 08:12 PM
pattern matching nadeemr Linux - Newbie 8 06-13-2007 12:05 PM
Perl pattern matching in VB rigel_kent Programming 1 05-30-2006 12:00 PM
Perl Pattern Matching Question pete1234 Programming 2 08-27-2005 11:26 AM
pattern matching in perl ludeKing Programming 9 04-02-2004 10:53 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration