|
|
|
|
|
|
| Author |
Message |
John DuBois *nix forums addict
Joined: 30 Mar 2005
Posts: 61
|
Posted: Thu Jul 20, 2006 5:35 pm Post subject:
Re: A program to quote like bash?
|
|
|
In article <1153349122.562734.18700@i3g2000cwc.googlegroups.com>,
<andrew.fabbro@gmail.com> wrote:
| Quote: | I have a directory with files full of parentheses, spaces, etc. If I'm
in bash I can type cp Blah<TAB> and bash quotes it all very nicely.
Now what I want to do is something like...
find /someplace -print > /tmp/list
magic happens
everything in the file is now quoted just like bash
...with the idea that such a file could then be used in various other
operations without getting a lot of errors due to &, (, ), spaces,
quotes, etc.
I can't seem to find, or even think of, a tool that would do this...?
|
I use something like this - it does a bit of extraneous quoting in some
cases, but it works:
awk '/[^-0-9A-Za-z_.\/:+]/{gsub("\047","&\\\\&&",$0);$0="\047"$0"\047"}1'
Also, see the %q formatter to the internal printf in bash (and ksh93).
John
--
John DuBois spcecdt@armory.com KC6QKZ/AE http://www.armory.com/~spcecdt/ |
|
| Back to top |
|
 |
survivalist@gmail.com *nix forums beginner
Joined: 22 Dec 2005
Posts: 4
|
Posted: Thu Jul 20, 2006 10:30 am Post subject:
Re: A program to quote like bash?
|
|
|
James Michael Fultz wrote:
| Quote: | If you don't mind some characters being unnecessarily quoted, the
following would do:
find /someplace -print | sed 's,[^/a-zA-Z0-9._-],\\&,g' > /tmp/list
|
That's probably the best route...better to say what's legal than what's
not, since the latter usually only works until you come across
something that should have been on the list ;)
| Quote: | If you could tell us what you're trying to do, there might be alternate
approaches.
Using the `-exec' option with find may work for your situation. Since
you mentioned bash, perhaps GNU find and GNU xargs are available to you
as well. You may be able to use `-print0' with find and `-0' with xargs
to solve the problem.
|
Yes, those are all good choices. I guess I was asking if there was a
generalized tool that said "quote this string so it can be used on the
command line". In this case, I have a few thousand files that need to
be moved (one-time) to different directories. There's no way to do it
except by looking at the file list...so I thought to dump the list into
a text file, vi the file to make it into a shell script. Multiple
finds, etc. could also do it...
Anyway, it seems there should be some sort of generalized tool for this
purpose. Alas, I'll have to add it to my list of things to do in my
copious spare time ;)
Thanks! |
|
| Back to top |
|
 |
James Michael Fultz *nix forums beginner
Joined: 19 Feb 2005
Posts: 11
|
Posted: Thu Jul 20, 2006 6:54 am Post subject:
Re: A program to quote like bash?
|
|
|
* <andrew.fabbro@gmail.com>:
| Quote: | I have a directory with files full of parentheses, spaces, etc. If I'm
in bash I can type cp Blah<TAB> and bash quotes it all very nicely.
Now what I want to do is something like...
find /someplace -print > /tmp/list
magic happens
everything in the file is now quoted just like bash
|
If you don't mind some characters being unnecessarily quoted, the
following would do:
find /someplace -print | sed 's,[^/a-zA-Z0-9._-],\\&,g' > /tmp/list
Alternately, a pattern matching special characters could be used but is
messier. Also, I be leaving out something here:
find /someplace -print |
sed 's,[][|&;()<>[:blank:]*?\\'\''"$~!],\\&,g' > /tmp/list
| Quote: | ...with the idea that such a file could then be used in various other
operations without getting a lot of errors due to &, (, ), spaces,
quotes, etc.
|
If you could tell us what you're trying to do, there might be alternate
approaches.
Using the `-exec' option with find may work for your situation. Since
you mentioned bash, perhaps GNU find and GNU xargs are available to you
as well. You may be able to use `-print0' with find and `-0' with xargs
to solve the problem.
--
James Michael Fultz <xyzzy@sent.as.invalid>
Remove this part when replying ^^^^^^^^ |
|
| Back to top |
|
 |
andrew.fabbro@gmail.com *nix forums beginner
Joined: 13 Feb 2005
Posts: 6
|
Posted: Wed Jul 19, 2006 10:45 pm Post subject:
A program to quote like bash?
|
|
|
I have a directory with files full of parentheses, spaces, etc. If I'm
in bash I can type cp Blah<TAB> and bash quotes it all very nicely.
Now what I want to do is something like...
find /someplace -print > /tmp/list
<magic happens>
<everything in the file is now quoted just like bash>
....with the idea that such a file could then be used in various other
operations without getting a lot of errors due to &, (, ), spaces,
quotes, etc.
I can't seem to find, or even think of, a tool that would do this...?
Thanks. |
|
| Back to top |
|
 |
Google
|
|
| Back to top |
|
 |
|
|
The time now is Thu Dec 04, 2008 2:44 am | All times are GMT
|
|
Credit Cards | MPAA | Mortgage Calculator | Loan | Mobile Phones
|
|
Copyright © 2004-2005 DeniX Solutions SRL
|
|
|
|
Other DeniX Solutions sites:
Unix/Linux blog |
electronics forum |
medicine forum |
science forum |
|
|
Privacy Policy
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|