cp: omitting directory, for copying only files, sed

Edgar Matzinger edgar@edgar-matzinger.nl
Sun Nov 7 16:50:00 GMT 2010


-----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="\/Users\/edgarm\/tmp\/$1\/."
>> echo $W
>> sed -n 's/^File[ ]*\([^ ][^ ]*\).*/\"\1\" '"$W"'/p' < $2 | xargs  
>> echo X:

I would replace your script with this one:

#!/bin/sh
W="\/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

What does it do?

- -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

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=
=9RNs
-----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



More information about the Cygwin mailing list