Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 01-18-2012, 05:02 AM   #1
Registered: Oct 2006
Location: The Ether
Distribution: Lubuntu 14.04 LTS, Kali
Posts: 297

Rep: Reputation: 30
Perl one liner - problem with printing captured regex on new line

I have a txt file , email.txt, full of data in the following format and I basically want to extract all the email addresses.
The one-liner I use is :
uncle-c@home:~/Perl/$ perl -ne '/^<(.*)>/ && print $1 ' email.txt 
What looks obvious here is that output of each regex capture needs to be put on a new line for clarity. I've tried alterations along the lines of print $1\n etc but I'm not getting anywhere. Prob something very simple and obvious so apologies for my ignorance :-)
What would really help would be what I am doing wrong and and an explanation of the solution. I am just starting off learning Perl ( self taught) so any input is very very useful.


Last edited by uncle-c; 01-20-2012 at 03:57 AM.
Old 01-18-2012, 05:08 AM   #2
Senior Member
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 243Reputation: 243Reputation: 243
You have to add double quotes, so the "\n" char is interpreted

perl -ne '/^<(.*)>/ && print "$1\n"' email.txt
1 members found this post helpful.
Old 01-18-2012, 05:15 AM   #3
Registered: Oct 2006
Location: The Ether
Distribution: Lubuntu 14.04 LTS, Kali
Posts: 297

Original Poster
Rep: Reputation: 30
Thanks Cedrik ! I feel like complete dodo now but at least I will not forget this elementary mistake in the future.

Last edited by uncle-c; 01-18-2012 at 05:17 AM.


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
Perl - printing progress on same line. Technoslave Programming 7 09-03-2011 09:20 PM
[SOLVED] differences between shell regex and php regex and perl regex and javascript and mysql golden_boy615 Linux - General 2 04-19-2011 01:10 AM
Perl: Multiple line regex matching sammywammy Programming 4 02-09-2011 10:03 AM
Define Perl Regex Logical Line craig467 Programming 3 07-20-2008 10:15 PM
PERL editing single line in file with regex indiescene Programming 0 04-14-2004 08:18 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:20 AM.

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