The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 10-07-2007
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
  
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
A few solutions

awk:
Code:
$ awk '{s=$0;gsub( /^.*\//, "" );printf("cp -pr %s %s\n", $0, s )}' abc
cp -pr a.dbf /data/a.dbf
cp -pr b.dbf /data/june/b.dbf
sed:
Code:
$ sed 's!^\(.*\)/\(.*\)!cp -pr \2 \1/\2!' abc 
cp -pr a.dbf /data/a.dbf
cp -pr b.dbf /data/june/b.dbf
bash/ksh:
Code:
$ while read file; do echo "cp -pr ${file##*/} ${file}"; done < abc 
cp -pr a.dbf /data/a.dbf
cp -pr b.dbf /data/june/b.dbf