| www.delorie.com/archives/browse.cgi | search |
| X-Recipient: | archive-cygwin AT delorie DOT com |
| X-SWARE-Spam-Status: | No, hits=0.8 required=5.0 tests=BAYES_50,RCVD_IN_DNSWL_NONE |
| X-Spam-Check-By: | sourceware.org |
| Message-Id: | <0A09BBFB-0267-4D0B-B736-4F8AB8B84C32@edgar-matzinger.nl> |
| From: | Edgar Matzinger <edgar AT edgar-matzinger DOT nl> |
| To: | cygwin AT cygwin DOT com |
| In-Reply-To: | <ib695r$uer$1@dough.gmane.org> |
| Mime-Version: | 1.0 (Apple Message framework v936) |
| Subject: | Re: cp: omitting directory, for copying only files, sed |
| Date: | Sun, 7 Nov 2010 17:49:52 +0100 |
| References: | <ib3gtb$v4$1 AT dough DOT gmane DOT org> <6488B010-E946-4EA3-BE77-586ACD794EEB AT edgar-matzinger DOT nl> <ib695r$uer$1 AT dough DOT gmane DOT org> |
| X-Pgp-Agent: | GPGMail 1.2.0 (v56) |
| X-IsSubscribed: | yes |
| Mailing-List: | contact cygwin-help AT cygwin DOT com; run by ezmlm |
| List-Id: | <cygwin.cygwin.com> |
| List-Unsubscribe: | <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com> |
| List-Subscribe: | <mailto:cygwin-subscribe AT cygwin DOT com> |
| List-Archive: | <http://sourceware.org/ml/cygwin/> |
| List-Post: | <mailto:cygwin AT cygwin DOT com> |
| List-Help: | <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs> |
| Sender: | cygwin-owner AT cygwin DOT com |
| Mail-Followup-To: | cygwin AT cygwin DOT com |
| Delivered-To: | mailing list cygwin AT cygwin DOT com |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi David,
On 7 Nov 2010, at 14:22, David wrote:
> Den 06-11-2010 15:12, Edgar Matzinger skrev:
>> I ran this script (on MacOSX):
>>
>> #!/bin/sh
>> W=3D"\/Users\/edgarm\/tmp\/$1\/."
>> echo $W
>> sed -n 's/^File[ ]*\([^ ][^ ]*\).*/\"\1\" '"$W"'/p' < $2 | xargs=20=20
>> echo X:
I would replace your script with this one:
#!/bin/sh
W=3D"\/Users\/edgarm\/tmp\/$1\/."
echo $W
sed -n -e '/^File/H' -e '${x; s:\n: :g; s:File ::g; s:\(.*\):\1=20=20
"'$W'":; p; }' < $2 | xargs cp
What does it do?
- -e '/^File/H' When pattern buffer starts with 'File', append it to=20=20
hold buffer
- -e '${ When at the last line, start a function
x; Exchange hold and pattern buffer
s:\n: :g; Replace newline with a space
s:File ::g; Delete 'File '
s:\(.*\):\1 "'$W'":;
Append $W to pattern buffer
p; }' Print pattern buffer and close function
Note: The pattern buffer is also the input buffer.
Thanks for a nice sed training or exercise...
Kind regards, Edgar.
- --
''~``
( o o )
+-------------------------------------------------.oooO--(_)--Oooo.---+
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Darwin)
iQEcBAEBAgAGBQJM1tixAAoJEENMxv7g8VYweG0H/2fT04z1+flFjd8YI3phOeA2
kGSZ9pSQBbRWRsa/lvLnKDoipMeTatYrG2vnzRz1/NGWg7XB0WpGGTn111NYIzQd
ljl40zSCKC825zQWH7VdGFC2tk24Rktzbz/KTWDyVHIdvaBp9C6O4JsAbBFOgiZE
8/3QtkhD/g1dPMM5P0rUGXUfRDRB5Z9OnV1w5g2HU5I4+3SWdD/5VjEOTZ2JNcXT
nkC0D/ADzwCPRHSFPwFyRYWEWRxhZdeUQUDd+NCsmvLapVkooz0WLZbS6dhq9KUs
I80vO2dVsZCzZVL99AH6BURG/yYZCCBA/7FU91MuCzPBUVpY5aFXdSaioZEduH4=3D
=3D9RNs
-----END PGP SIGNATURE-----
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |