Re: piping multiple selections to mv or cp and exclusion
- From: "tony" <ccahua@xxxxxxxxx>
- Date: 26 Oct 2006 22:23:17 -0700
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.
.
- Follow-Ups:
- Re: piping multiple selections to mv or cp and exclusion
- From: Dean G.
- Re: piping multiple selections to mv or cp and exclusion
- References:
- piping multiple selections to mv or cp and exclusion
- From: tony
- Re: piping multiple selections to mv or cp and exclusion
- From: Pierre Barbier de Reuille
- Re: piping multiple selections to mv or cp and exclusion
- From: Janis Papanagnou
- Re: piping multiple selections to mv or cp and exclusion
- From: Spiros Bousbouras
- Re: piping multiple selections to mv or cp and exclusion
- From: Janis Papanagnou
- Re: piping multiple selections to mv or cp and exclusion
- From: tony
- Re: piping multiple selections to mv or cp and exclusion
- From: Dean G.
- piping multiple selections to mv or cp and exclusion
- Prev by Date: Re: How can I get the last argument of the command line ?
- Next by Date: size of all files combined
- Previous by thread: Re: piping multiple selections to mv or cp and exclusion
- Next by thread: Re: piping multiple selections to mv or cp and exclusion
- Index(es):
Relevant Pages
|