Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > macOS > ack! Help with awk!

ack! Help with awk!
Thread Tools
muchfresh
Mac Enthusiast
Join Date: Jan 2001
Location: ny ny usa
Status: Offline
Reply With Quote
Jul 20, 2002, 06:45 PM
 
I am trying to move all my mp3 files to one directory. Itunes 3 screwed up my organization. So I built a list of all my mp3 files with:

</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">find /Users/chico -name &quot;*.mp3&quot; &gt; list</pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">I would like to build a list of commands with awk to move each file to the current directory.

</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">awk '{print &quot;mv '&quot;, $0, &quot;' .&quot;}' list &gt; cmd</pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">unfortunatly *all* my .mp3 files have white spaces in their names. so I need to wrap the file name in '. But the ' char is reserved by awk.
'Satisfy the urge and discover the need' Q-Tip
     
thanatos
Dedicated MacNNer
Join Date: Sep 2000
Status: Offline
Reply With Quote
Jul 20, 2002, 07:06 PM
 
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">Originally posted by muchfresh:
<strong>I am trying to move all my mp3 files to one directory. Itunes 3 screwed up my organization. So I built a list of all my mp3 files with:

</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">find /Users/chico -name &quot;*.mp3&quot; &gt; list</pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">I would like to build a list of commands with awk to move each file to the current directory.

</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">awk '{print &quot;mv '&quot;, $0, &quot;' .&quot;}' list &gt; cmd</pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">unfortunatly *all* my .mp3 files have white spaces in their names. so I need to wrap the file name in '. But the ' char is reserved by awk.</strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">I'm not good with awk but have you tried to put a backslash infront of ' ?
     
muchfresh  (op)
Mac Enthusiast
Join Date: Jan 2001
Location: ny ny usa
Status: Offline
Reply With Quote
Jul 20, 2002, 07:27 PM
 
backslash, fowardslash and double quotes do not work.
'Satisfy the urge and discover the need' Q-Tip
     
Camelot
Mac Elite
Join Date: May 1999
Location: San Jose, CA
Status: Offline
Reply With Quote
Jul 20, 2002, 07:56 PM
 
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">Originally posted by muchfresh:
<strong>I am trying to move all my mp3 files to one directory. Itunes 3 screwed up my organization. So I built a list of all my mp3 files with:

</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">find /Users/chico -name &quot;*.mp3&quot; &gt; list</pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">I would like to build a list of commands with awk to move each file to the current directory.

</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">awk '{print &quot;mv '&quot;, $0, &quot;' .&quot;}' list &gt; cmd</pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">unfortunatly *all* my .mp3 files have white spaces in their names. so I need to wrap the file name in '. But the ' char is reserved by awk.</strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">Leaving the awk syntax question aside for a moment, why are you using awk at all?

From reading the scripts, you're using find to generate a file containing all the .mp3s on your system, you're then using awk to generate another file containing a slew of mv commands.

You are aware that find can make the move for you, aren't you?

using find's -exec switch, you can execute any shell command on each match.

for example:

find /Users/chico -name "*.mp3" -exec mv {} /path/to/new/location \;

In the above example, each found match will execute the "mv {} /path/to/new/location" command (note that {} is substituted with the filename matched by the find command).
Gods don't kill people - people with Gods kill people.
     
skipjack
Dedicated MacNNer
Join Date: Oct 2000
Status: Offline
Reply With Quote
Jul 21, 2002, 03:07 AM
 
Here's guessing at something I know little about ...

It isn't an awk problem. It's a shell problem. The tcsh and csh don't allow (all? any?) escape characters.

bash will let you escape characters.
     
   
 
Forum Links
Forum 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
Top
Privacy Policy
All times are GMT -4. The time now is 04:20 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,