Re: piping multiple selections to mv or cp and exclusion



Hi,

I finally found something that worked for me in unixkit, if anyone has
the same issue.

Once a list of selected files is found from regex, find, egrep, comm or
other tools, redirect the list to a file, say, resultset.txt

Here's the clunky script to copy the filenames in resultset to the
directory named 'newdir':

sed 's/^/cp /' resultset.txt | sed 's/$/ newdir/' | bash

What it does:
Basically it brackets each filename with 'cp' and 'newdir' so there is
a command for each file:

1 prepend cp to all lines of resultset and pipe stdout to statement 2
2 append newdir or name of directory where you want the files to go to
each line
3 pipe to shell to execute each command statement

I couldn't figure out how to make it shorter, but at least it works.

Then today I found this post that uses loops to process multiple files:
http://www.basicallytech.com/blog/index.php?/archives/10-Shell-stuff-rename-multiple-files-on-the-command-line.html

Unix is indeed lifelong learning :-)

Best,
tony

Dean G. wrote:
tony wrote:
Thank you for all your helpful replies and pointers to xargs, find exec
and the regexp.

Unfortunately the unix ports (http://jlb.twu.net/code/unixkit.php) that
allow me to use unix utilities on a corporate Windows machine doesn't
have man pages or xargs so I've been trying to add unxutils
(http://unxutils.sourceforge.net/) as needed as I learn.

I picked up basic unix books at the library, bought Chris Johnson's
Shell recipes book and I'll read up on the man pages on the net so that
will help too. Even though I'm training myself to use the command line
more, the crazy thing is that I'm using bloated programs like Excel or
features of a text editor to say parse the stdout of ls so I can paste
it back into the command line?! ie ls -1 > file then copy paste in text
editor and replace all line feeds with pipes | to get a string to paste
back into the grep statement.

Are you grepping the same thing out of each file, or grepping the file
names from another location ? If the former, then

grep <regexp> `ls -1`
or (since you are just using ls -1 with no arguments)
grep <regexp> *

should work.

If the later, then consider using grep with the -f option for the
expresion file. It can save you the trouble of pasting the string
together, because the expression file is a list separated by line
feeds, which seems to be what you have.

grep -f <expfile> <filelist>

Dean G.

.



Relevant Pages

  • Re: MacTeX 2007 and documentation
    ... may be the most useful command available when doing searches at the ... will find every file on your system that has the text "memoir" on it, ... If locate generates 30 lines of text, where each line is a file, grep ... I need a Unix guru to chat to for half an hour or so to put me straight. ...
    (comp.text.tex)
  • Re: piping multiple selections to mv or cp and exclusion
    ... and the regexp. ... allow me to use unix utilities on a corporate Windows machine doesn't ... back into the grep statement. ... expresion file. ...
    (comp.unix.shell)
  • Re: Easy Question (grep and sed)
    ... > I have one question for Unix lovers, it is so simple and easy for who ... > I know that grep command detect if the R.E matched or not and return a ... > is a small part in a script) using grep, egrep, or a simple awk ...
    (comp.unix.shell)
  • Re: grep command
    ... On Thursday 9 April 2009 06:26, unix baby wrote: ... Is there any way in which I can exclude a particular file while using ... I want to usue the command grep unix -r *. ...
    (comp.unix.shell)
  • Re: Determining filetype
    ... The "file" command on unix should tell you if the file is text or ... You could also do it with a regexp: ... binary or ascii data other than by examining its extension? ...
    (comp.lang.php)

Quantcast