delorie.com/archives/browse.cgi | search |
X-Recipient: | archive-cygwin AT delorie DOT com |
X-SWARE-Spam-Status: | No, hits=-1.6 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SARE_FREE_WEBM_LAPOSTE,T_RP_MATCHES_RCVD,T_TO_NO_BRKTS_FREEMAIL |
X-Spam-Check-By: | sourceware.org |
Message-ID: | <4CD74321.3060902@laposte.net> |
Date: | Mon, 08 Nov 2010 01:24:01 +0100 |
From: | Cyrille Lefevre <cyrille DOT lefevre-lists AT laposte DOT net> |
User-Agent: | Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.8.1.3) Gecko/20070326 Thunderbird/2.0.0.0 Mnenhy/0.7.5.666 |
MIME-Version: | 1.0 |
To: | cygwin AT cygwin DOT com |
Subject: | Re: cp: omitting directory, for copying only files, sed |
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> <0A09BBFB-0267-4D0B-B736-4F8AB8B84C32 AT edgar-matzinger DOT nl> |
In-Reply-To: | <0A09BBFB-0267-4D0B-B736-4F8AB8B84C32@edgar-matzinger.nl> |
X-me-spamlevel: | not-spam |
X-me-spamrating: | 36.000000 |
X-me-spamcause: | OK, (-100)(0000)gggruggvucftvghtrhhoucdtuddrfedtiedruddtucetggdotefuucfrrhhofhhilhgvmecuoehnohhnvgeqnecuuegrihhlohhuthemuceftddtnecuucdlqddutddtmd |
X-IsSubscribed: | yes |
Mailing-List: | contact cygwin-help AT cygwin DOT com; run by ezmlm |
List-Id: | <cygwin.cygwin.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 |
Le 07/11/2010 17:49, Edgar Matzinger a =E9crit : > 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 echo X: >=20 > I would replace your script with this one: >=20 > #!/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 "'$W'":; > p; }' < $2 | xargs cp >=20 > What does it do? >=20 > - -e '/^File/H' When pattern buffer starts with 'File', append it to > 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 >=20 > Note: The pattern buffer is also the input buffer. take care that the hold buffer may be limited in size, see "info sed Limitations" for details. that mean that legacy sed may break if the file list is too long. gnu sed has no such limitations, but remember you such limitations. well, 2 alternatives w/o such limitation : this one is a little less performant than the one provided due to multiple fork, but a little simple : sed -ne 's|\\|/|g;/^File /s///p' $2 | xargs -I{} echo cp {} "$W" cp ../test/file1.txt /path/to cp ../test/file2.txt /path/to -n don't print anything except if asked for (see p) s|\\|/|g \ =3D> / /^File / do the following subsitution only on mached line s/// substitute 'File ' w/ nothing, yep, if the search pattern is not provided, the last one is used p print the pattern buffer if a substitution has occured there is no ; between /^File/...p, this is normal. this one needs a GNU cp which support the -t option : sed -ne 's|\\|/|g;/^File /s///p' $2 | xargs echo cp -t "$W" cp -t /path/to ../test/file1.txt ../test/file2.txt Regards, Cyrille Lefevre --=20 mailto:Cyrille DOT Lefevre-lists AT laposte DOT net -- 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 |