LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-19-2013, 02:46 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
sed match none greedy


Hi, how do I match:
Code:
2005-12-15+19:16:32.0000000000  /mnt/main//GUNxSWORD(Music)/13 Bitter Dream
2005-12-15+19:16:32.0000000000  /mnt/maerawerawer/GUNxSWO RD(Music)/12 Hearts Together
I wish to use sed to replace the long string of numbers in the front. Such that:
Code:
/mnt/main//GUNxSWORD(Music)/13 Bitter Dream
/mnt/maerawerawer/GUNxSWO RD(Music)/12 Hearts Together
are the results, this seems like that I only want to match the first space and don't want the match to get the 2nd or spaces after words.
I've tried:
sed 's:^.*\s::i'
but it doesnt work.
Thanks,
Ted
 
Old 02-19-2013, 02:53 AM   #2
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
The regular expression .*\s matches all the characters until the last space (spaces included). You have to exclude the space from the character list in order to match all the chracters until the first space, e.g.
Code:
sed 's/^[^ ]* //' file
Not sure about matching only the first space and not the second one. According to the desired output you should match any number of spaces after the first string, that is
Code:
sed -r 's/^[^ ]* +//' file
Hope this helps.
 
1 members found this post helpful.
Old 02-19-2013, 02:57 AM   #3
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
If I understood your requirement correctly, then you can:
Code:
~$ awk -F" " '{print $1,$2,$3,$4,$5}' infile.txt
 
1 members found this post helpful.
Old 02-19-2013, 03:10 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 for everyone's help here. colucix's first code seems to got me very close:
Code:
2003-09-29+08:39:08.0000000000  /mnt/main/media/music/主題曲/灌籃少年/Dear Boys OST - Love & Chasing/04 - Seishun In the Starlight.mp3
2003-09-29+08:29:12.0000000000  /mnt/main/media/music/主題曲/灌籃少年/Dear Boys OST - Love & Chasing/02 - Go Go Goal.mp3
2003-09-29+08:08:50.0000000000  /mnt/main/media/music/主題曲/灌籃少年/Dear Boys OST - Love & Chasing/03 - Promise.mp3
2003-09-29+08:07:28.0000000000  /mnt/main/media/music/主題曲/灌籃少年/Dear Boys OST - Love & Chasing/05 - Love and Chasing.mp3
2000-06-13+18:26:45.2655000000  /mnt/main/media/music/英文歌/how do i breathe.mp3
gave me
Code:
Boys OST - Love & Chasing/01 - Shake It Up.mp3
Boys OST - Love & Chasing/04 - Seishun In the Starlight.mp3
Boys OST - Love & Chasing/02 - Go Go Goal.mp3
Boys OST - Love & Chasing/03 - Promise.mp3
Boys OST - Love & Chasing/05 - Love and Chasing.mp3
do i breathe.mp3
but I wish to get the space prior toe that:
Code:
/mnt/main/media/music/主題曲/灌籃少年/Dear Boys OST - Love & Chasing/04 - Seishun In the Starlight.mp3
/mnt/main/media/music/主題曲/灌籃少年/Dear Boys OST - Love & Chasing/02 - Go Go Goal.mp3
/mnt/main/media/music/主題曲/灌籃少年/Dear Boys OST - Love & Chasing/03 - Promise.mp3
/mnt/main/media/music/主題曲/灌籃少年/Dear Boys OST - Love & Chasing/05 - Love and Chasing.mp3
/mnt/main/media/music/英文歌/how do i breathe.mp3
Thanks, Ted
sorry for the mandarin.
 
Old 02-19-2013, 03:41 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
sorry my bad, the :
Code:
2003-09-29+08:39:08.0000000000  /mnt/main/media/music/主題曲/灌籃少年/Dear Boys OST - Love & Chasing/04 - Seishun In the Starlight.mp3
2003-09-29+08:29:12.0000000000  /mnt/main/media/music/主題曲/灌籃少年/Dear Boys OST - Love & Chasing/02 - Go Go Goal.mp3
2003-09-29+08:08:50.0000000000  /mnt/main/media/music/主題曲/灌籃少年/Dear Boys OST - Love & Chasing/03 - Promise.mp3
2003-09-29+08:07:28.0000000000  /mnt/main/media/music/主題曲/灌籃少年/Dear Boys OST - Love & Chasing/05 - Love and Chasing.mp3
2000-06-13+18:26:45.2655000000  /mnt/main/media/music/英文歌/how do i breathe.mp3
is not a space but a tab /t thus:
sed 's:^.*\t::g'
simply did the trick, but 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
[SOLVED] non greedy match in sed rounded brackets exactiv Linux - General 8 08-23-2012 05:21 PM
Using sed to replace a second match before a match nithintou Programming 4 08-21-2012 06:48 AM
[SOLVED] sed string matching less greedy drj000 Programming 11 04-16-2010 02:50 AM
can't get non-greedy matching to work in sed lumix Linux - Newbie 3 05-05-2008 07:12 PM
grep/sed/awk - find match, then match on next line gctaylor1 Programming 3 07-11-2007 08:55 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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