- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Creating a script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2002 08:54 AM
08-26-2002 08:54 AM
for each item
cp -r (item in file1) (item in file2)
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2002 09:10 AM
08-26-2002 09:10 AM
Re: Creating a script
It would be convenient to have both files merged into one, named file, such that each line has two items delimited by whitespace. The first example covers this approach:
#!/usr/bin/sh
while read item1 item2
do
cp -pr $item1 $item2
done < file
To use separate files of identical length and order, this should work:
#!/usr/bin/sh
exec 3< file1
exec 4< file2
while read -u3 item1
do
if read -u4 item2
then
cp -pr $item1 $item2
fi
done
exec 3<&-
exec 4<&-
More can be done to test for the existence of the source files/directories and the ability to create the target locations.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2002 09:12 AM
08-26-2002 09:12 AM
Re: Creating a script
assuming filenames are unique in each file :
you could run a script like :
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#!/bin/sh
for filename in `cat file1`
do
echo $filename
f1=`basename $filename`
f2=`grep $f1 file2`
cmd="cp $filename $f2"
echo $cmd
done
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This also assume all the file names exist.
in file1 is a list of pathnames
in file2 is a list of target pathnames
instead of echo $cmd use eval $cmd.
Try it in your test environment 1st.
Hope this help
Jean-Luc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2002 09:12 AM
08-26-2002 09:12 AM
Solutionpaste file1 file2 | xargs -n2 cp -r
If file1 is
aaa
bbb
and file2 is
ccc
ddd
then the result is-
aaa
bbb
is pipe to xargs, which will then generate-
cp -r aaa ccc
cp -r bbb ddd
Hope this helps...
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2002 09:28 AM
08-26-2002 09:28 AM
Re: Creating a script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2002 09:34 AM
08-26-2002 09:34 AM