LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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-23-2005, 08:46 AM   #1
dangerousdave
Member
 
Registered: Feb 2005
Distribution: Ubuntu 8.04
Posts: 100

Rep: Reputation: 15
Using grep, etc to modify a text file


OK, heres the situation. I have my mp3s on an ntfs (read only) drive. I copied the m3u playlist to my linux drive so I can edit it. Aside from replacing all '\' with '/' I need to now point the files in the playlist to the directory on the ntfs drive (as the mp3s are no longer local)

E.g. A line that says "Natalie Imbruglia - Torn (MTV's Live And Loud).mp3" has to be changed to "/mnt/windows/shared/music/mp3/Natalie Imbruglia - Torn (MTV's Live And Loud).mp3".

There are lines beginning with a '#' that I need to ignore (alternate lines with # and file name).

I managed to get all lines from the file that dont begin with '#' by using grep -v '#' best7_linux.m3u. But now I'm stuck... how do I add /mnt/windows..etc to the front of each line then put that back into the file (or into a new one)?

I really dont want to have to create a new playlist, since the songs I listen to are a fraction of what I have in my mp3 directory... I dont want to add them all and have to sift through 1000's deleting ones I dont want to listen to.

I'm pretty sure you can do this through linux shell, or at least through a script. If anyone can post the commands or a link to a decent tutorial that would be brilliant.

Cheers.
 
Old 02-23-2005, 08:56 AM   #2
uman
Member
 
Registered: Sep 2004
Distribution: Gentoo
Posts: 134

Rep: Reputation: 15
http://archive.ncsa.uiuc.edu/General...ing/PerlIntro/

Perl is the best tool for the job, in case you didn't know it's a scripting language well suited for text processing.


Cheers, and good luck!
 
Old 02-23-2005, 08:57 AM   #3
ranelson
LQ Newbie
 
Registered: Jan 2005
Posts: 8

Rep: Reputation: 0
Got AWK?

man awk

If that does not help get an awk book.
 
Old 02-23-2005, 09:58 AM   #4
Blinker_Fluid
Member
 
Registered: Jul 2003
Location: Clinging to my guns and religion.
Posts: 683

Rep: Reputation: 63
So if I got this right you want to change:
Natalie Imbruglia - Torn (MTV's Live And Loud).mp3
TO:
/mnt/windows/shared/music/mp3/Natalie Imbruglia - Torn (MTV's Live And Loud).mp3


You could do this with sed doing something like:
sed 's/^/\/mnt\/windows\/shared\/music\/mp3\//g' mp3_list
(mp3_list is the name of the file where I saved the list)
 
Old 02-23-2005, 01:10 PM   #5
osat3ch
Member
 
Registered: Jan 2004
Location: Portsmouth, NH
Distribution: FC3, FC4
Posts: 45

Rep: Reputation: 15
i'd use find and replace

IF all the files are in the same folder I would find and replace

first I would find and replace " with "/mnt/windows/shared/music/mp3/
and then I would find and replace .mp3"/mnt/windows/shared/music/mp3/ with .mp3"


hope this helps
 
Old 02-23-2005, 01:33 PM   #6
dangerousdave
Member
 
Registered: Feb 2005
Distribution: Ubuntu 8.04
Posts: 100

Original Poster
Rep: Reputation: 15
Wow, cheers for all the replies on this one.

In the end I downloaded java and wrote my own little program to do it... stick to what you know, eh. I am right now looking through those commands though, will be useful for future reference. Cheers again.
 
Old 02-23-2005, 02:02 PM   #7
iGoo
LQ Newbie
 
Registered: Feb 2005
Posts: 4

Rep: Reputation: 0
awk, grep (and many forms of grep) and sed are all great text editing tools

personaly i find grep and awk the most useful, sed is out ther in my books :s
 
Old 02-23-2005, 02:49 PM   #8
Blinker_Fluid
Member
 
Registered: Jul 2003
Location: Clinging to my guns and religion.
Posts: 683

Rep: Reputation: 63
Quote:
Originally posted by iGoo
awk, grep (and many forms of grep) and sed are all great text editing tools

personaly i find grep and awk the most useful, sed is out ther in my books :s
I got used to sed and grep and awk is one of those I have to think about and check my notes on.
 
  


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
how to modify a text file or a string in shell programming luckyvietman Programming 5 07-12-2005 05:08 PM
How to search and replace a text using grep DediPlace Linux - General 2 05-29-2005 06:47 PM
modify text of an jpg file on linux with gimp 2.0.4 tcma Linux - Software 1 10-19-2004 11:12 AM
remove text with grep craigdolson Linux - General 6 04-21-2004 03:25 PM
modify file access & modify timestamps i2itstud Linux - General 1 05-20-2003 03:34 AM

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

All times are GMT -5. The time now is 09:22 PM.

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