LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 04-08-2011, 04:25 AM   #1
ted_chou12
Member
 
Registered: Aug 2010
Location: Zhongli, Taoyuan
Distribution: slackware, windows, debian (armv4l GNU/Linux)
Posts: 430
Blog Entries: 28

Rep: Reputation: 2
one more regex problem sorry


Hi, I want to match any strings like:
Code:
...contents...
Wrote file /tmp/1-MMmxI7E
Red variable region

This is always at the start of the line, I have come up with a matching pattern, but this grabs the whole line instead of only "/tmp/1-MMmxI7E"
Code:
echo "$(cat "/var/mail/root/torrents/81A3A9.torrent" | sed -n '/^Wrote file/{ /.*/p}' )"
eg:"Wrote file /tmp/1-MMmxI7E" but I just want "/tmp/1-MMmxI7E" portion.
THanks,
Ted

Last edited by ted_chou12; 04-08-2011 at 04:32 AM.
 
Old 04-08-2011, 04:52 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,592

Rep: Reputation: 2915Reputation: 2915Reputation: 2915Reputation: 2915Reputation: 2915Reputation: 2915Reputation: 2915Reputation: 2915Reputation: 2915Reputation: 2915Reputation: 2915
Yeah you still need a removal:
Code:
sed -n '/^Wrote file/s|[^/]*//p' file
Also, you should get out of the habit of using cat it serves no purpose here.
 
1 members found this post helpful.
Old 04-08-2011, 04:52 AM   #3
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,825
Blog Entries: 1

Rep: Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221
edit: Nevermind, grail provided a shorter and better solution
 
1 members found this post helpful.
Old 04-08-2011, 04:56 AM   #4
ted_chou12
Member
 
Registered: Aug 2010
Location: Zhongli, Taoyuan
Distribution: slackware, windows, debian (armv4l GNU/Linux)
Posts: 430
Blog Entries: 28

Original Poster
Rep: Reputation: 2
thanks!
 
Old 04-08-2011, 05:01 AM   #5
ted_chou12
Member
 
Registered: Aug 2010
Location: Zhongli, Taoyuan
Distribution: slackware, windows, debian (armv4l GNU/Linux)
Posts: 430
Blog Entries: 28

Original Poster
Rep: Reputation: 2
Quote:
Originally Posted by grail View Post
Yeah you still need a removal:
Code:
sed -n '/^Wrote file/s|[^/]*//p' file
Also, you should get out of the habit of using cat it serves no purpose here.
Hi, this returned empty string :/
the contents that I am tring to match is in the file "/var/mail/root/torrents/81A3A9.torrent"
so it is actually:
Code:
$ cat "/var/mail/root/torrents/81A3A9.torrent"
From: Chou Ted <ted_chou12@hotmail.com>
To: <daemon@tedchou12.cz.cc>
Subject: FW: test
Date: Thu, 7 Apr 2011 21:12:08 -0700


Cannot handle any part of multipart/alternative message


This message contains 'application/octet-stream`-format data.

which is being decoded and written to the file named "/tmp/1-MMrPxg6".
If you do not want this data, you probably should delete that file.
Wrote file /tmp/1-MMrPxg6
The part is the only part I want and it's variable.
Thanks!
Ted
 
Old 04-08-2011, 05:08 AM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Assuming the file name does not contain spaces:
Code:
sed -nr 's/Wrote file ([^[:space:]]+).*/\1/p' /var/mail/root/torrents/81A3A9.torrent
 
1 members found this post helpful.
Old 04-08-2011, 05:14 AM   #7
ted_chou12
Member
 
Registered: Aug 2010
Location: Zhongli, Taoyuan
Distribution: slackware, windows, debian (armv4l GNU/Linux)
Posts: 430
Blog Entries: 28

Original Poster
Rep: Reputation: 2
Thank you!
 
Old 04-08-2011, 05:44 AM   #8
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,592

Rep: Reputation: 2915Reputation: 2915Reputation: 2915Reputation: 2915Reputation: 2915Reputation: 2915Reputation: 2915Reputation: 2915Reputation: 2915Reputation: 2915Reputation: 2915
My bad ... still had old copy stored in paste ... Should have been:
Code:
sed -n '/^Wrote file/s|[^/]*||p' file
 
1 members found this post helpful.
Old 04-08-2011, 11:33 AM   #9
ted_chou12
Member
 
Registered: Aug 2010
Location: Zhongli, Taoyuan
Distribution: slackware, windows, debian (armv4l GNU/Linux)
Posts: 430
Blog Entries: 28

Original Poster
Rep: Reputation: 2
Hi, np, it works perfect too! Thanks!!
Ted
 
  


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
Perl to find regex and print following 5 lines after regex casperdaghost Linux - Newbie 3 08-29-2010 08:08 PM
Problem with RegEx using sed citygrid Linux - Newbie 8 03-27-2010 09:17 PM
Regex.h problem in c++, segmentation fault vargadanis Programming 4 07-14-2008 05:36 PM
regex with sed to process file, need help on regex dwynter Linux - Newbie 5 08-31-2007 05:10 AM
regex problem with sed ta0kira Programming 7 06-20-2005 12:33 AM

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

All times are GMT -5. The time now is 09:49 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