LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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: 431
Blog Entries: 32

Rep: Reputation: 3
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: 10,008

Rep: Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193
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,836
Blog Entries: 1

Rep: Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251
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: 431

Original Poster
Blog Entries: 32

Rep: Reputation: 3
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: 431

Original Poster
Blog Entries: 32

Rep: Reputation: 3
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: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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: 431

Original Poster
Blog Entries: 32

Rep: Reputation: 3
Thank you!
 
Old 04-08-2011, 05:44 AM   #8
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,008

Rep: Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193
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: 431

Original Poster
Blog Entries: 32

Rep: Reputation: 3
Hi, np, it works perfect too! Thanks!!
Ted
 
  


Reply



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:35 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
Open Source Consulting | Domain Registration