LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-24-2002, 03:08 PM   #16
MasterC
LQ Guru
 
Registered: Mar 2002
Location: Salt Lake City, UT - USA
Distribution: Gentoo ; LFS ; Kubuntu ; CentOS ; Raspbian
Posts: 12,613

Original Poster
Rep: Reputation: 69

Very cool, thank you for the explaination.

I am now reading up on sed, another command you mentioned earlier, along with reading up and practicing with awk (or gawk).

Thanks for helping me out with this, and also showing me how to better use my box.

Cool
 
Old 11-24-2002, 03:52 PM   #17
moses
Senior Member
 
Registered: Sep 2002
Location: Arizona, US, Earth
Distribution: Slackware, (Non-Linux: Solaris 7,8,9; OSX; BeOS)
Posts: 1,152

Rep: Reputation: 50
No problem. Glad I could help.
 
Old 11-25-2002, 09:20 AM   #18
NSKL
Senior Member
 
Registered: Jan 2002
Location: Rome, Italy ; Novi Sad, Srbija; Brisbane, Australia
Distribution: Ubuntu / ITOS2008
Posts: 1,207

Rep: Reputation: 47
Ok, sorry but i have a "sub-question" and don't want to start a new thread. That is, what command would get rid of spaces in filenames and replace them with " - " (minus sign). I have about 3000 .mp3's some contain spaces that i would like to convert to minus or underscore signs. How would i go about doing this?
And MasterC can you point me to some quick guides on awk (gawk) and sed (or are you just reading the man pages?) Since im totally ignorant about these important programs, i just know they exist and they are important, but would like to make use of them too.
Thanks everyone!
-NSKL
 
Old 11-25-2002, 04:41 PM   #19
moses
Senior Member
 
Registered: Sep 2002
Location: Arizona, US, Earth
Distribution: Slackware, (Non-Linux: Solaris 7,8,9; OSX; BeOS)
Posts: 1,152

Rep: Reputation: 50
Ok. . . Well, there are ways and ways of doing this. . .

awk and sed are good to read up on, but without reading about regular
expressions, they won't mean much. . .
Get an O'Reilly book on regex, sed, awk, etc. . .

Here's a very dirty, inelegant, way to do what you want:
Code:
ls * | sed s/\ /_/g | awk '{ print $0,$0}' | sed s/_/'\\'\ /1 | sed s/_/'\\'\ /1 | grep _ > mvfiles

source mvfiles
It's dirty and inelegant because:

We first change all spaces to "_", pipe that to awk, which prints each
line twice, pipe that to sed, which converts the first "_" to "\ ", pipe that
to sed, whcih converts the second (really the first it sees) "_" to "\ ",
pipe that to grep to just pull out the lines with an _ in them, redirect the
output to a file, then source the file. This will only work for filenames
with two spaces in them. . . You'd have to find a better way to do this
that involves not caring how many spaces there are. You can do it in
awk, PERL, or whatever. . .

The above is really just an example to get you started, since it will not
work if filenames only have one space, since it would end up changing
both underscores back to spaces. . .

Last edited by moses; 11-25-2002 at 04:47 PM.
 
Old 11-26-2002, 10:09 AM   #20
NSKL
Senior Member
 
Registered: Jan 2002
Location: Rome, Italy ; Novi Sad, Srbija; Brisbane, Australia
Distribution: Ubuntu / ITOS2008
Posts: 1,207

Rep: Reputation: 47
Ok, i'll get a book... Thank you very much!
-NSKL
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to list contents of a .tar.gz without unzip? leontini Linux - General 14 04-21-2010 02:07 AM
cannot list directory contents kpachopoulos Linux - General 2 11-29-2005 05:24 PM
Samba - XP can't list folder contents p0tw0r Linux - Networking 1 05-31-2005 03:37 AM
won't list contents of cdrom gillmb Linux - Newbie 2 10-19-2004 02:09 PM
How to list total file size of a directory phil1076 Linux - General 3 12-18-2003 03:47 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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