[Novalug] where are they?

pereira ninorpereira@gmail.com
Sun Mar 8 17:56:49 EDT 2015


Joh,

the command you suggested last,

mv $(cat filelist) directory-for-files

works really well.

I did not know about the $(..) trick, that this can be
a variable that can be one of the two that 'mv' needs.

I learned a lot today, Thanks Jon and Peter: you really
went out of their way to clarify the issues.

Let's give them a virtual hand of applause ////////

Nino



On 03/08/2015 03:31 PM, Jon LaBadie via Novalug wrote:
> On Sun, Mar 08, 2015 at 02:41:58PM -0400, pereira via Novalug wrote:
>> 2: I wanted to move all text files to a directory UTF-files. So I tried
>>
>> file * | grep UTF
>>
>> which gives me the files that are text in UTF-8 format. These I wanted
>> to pipe to 'mv', but this file (as "file * | grep UTF | mv UTF-files") but
>> this didn't work even when I tried inserting a * and a < and a > in various
>> places.
>> So I put them in a file (with"file * | grep UTF | > UTF-list") and edited
>> the
>> file to remove the trailing part where grep confirms that is sees UTF.
>> Then, I tried "mv UTF-list UTF-files/." which only took the file UTF-list to
>> the UTF-files directory (duh), and then "cat UTF-list mv . UTF-files and
>> variants, but this just typed out the file (or tried to).
>>
>> What magic am I missing?
> The magic of command substitution.  It says "run this command and put
> its output on the command line of a different command".  You want
> a mv command structured as:
>
>    mv X Y Z UTF-files
>
> so the command substitution goes where the X Y Z is located.
>
> Command substitution is invoked with $(...) or the depricated `...`
>
> I like to get to the final command stepwise, using your shells
> command recall and edit features.  In your case you need to
> get a list of file names.  You have something like this:
>
> $ file * | grep UTF
> CyberPowerOrder:      news or mail, UTF-8 Unicode text
> nramail.html:         HTML document, UTF-8 Unicode text
> out-tiff.txt:         UTF-8 Unicode text
>
> You have to get rid of everything from the colon on,  recall
> your command line and add " | cut -d: -f1"  (or an equivalent
> awk command).
>
> $ file * | grep UTF | cut -d: -f1
> CyberPowerOrder
> nramail.html
> out-tiff.txt
>
> You have your list, mentally confirm you want to move them.
> Now put it in command substitution with your mv command.
> Recall the command line and add to the beginning "mv $("
> and to the end ") UTF-files
>
> $ mv $(file * | grep UTF | cut -d: -f1) UTF-files
> $
>
> I find this stepwise approach works well for me in a lot
> of situations.
>
> If you are more comfortable creating a file containing
> the list of names to move, you can still use command
> substitution, except the command would be $(cat filelist)
> or the equivalent $(<filelist).
>
>
> Jon




More information about the Novalug mailing list