- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Copying files for different instance names
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
Discussions
Discussions
Forums
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
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-25-2009 02:06 PM
тАО08-25-2009 02:06 PM
I need to copy a log file from /logs/{instance-name}/abc.log-08222009 to /tmp/
As "abc.log-08222009" name is same for all the instances it overwrites after copying to /tmp/ directory.
I want to append the instance name from source and assign it to destination file name.
Say for example:
cp /logs/venus/abc.log-08222009 /tmp/abc.log-08222009-venus
cp /logs/moon/abc.log-08222009 /tmp/abc.log-08222009-moon
As there are hundred of different instance names i want to copy using single command to save time.
Can someone suggest proper command or script ?
Thanks,
Shiv
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-25-2009 02:32 PM
тАО08-25-2009 02:32 PM
SolutionI can suggest a structure.
Make a file list and then process it.
ls -1 > list
while read -r fn
do
cp $fn /tmp/instance
done < list
You can expand on this.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-25-2009 02:52 PM
тАО08-25-2009 02:52 PM
Re: Copying files for different instance names
This is trivial with Perl.
# cat ./mycopy
#!/usr/bin/perl
use strict;
use warnings;
use File::Copy;
my ( $oldname, $newname );
while (<>) {
chomp( $oldname = $_ );
( $newname = $oldname ) =~ s{/logs/(.+)/(.+)}{/tmp/$2-$1};
copy( $oldname, $newname ) or warn "Can't copy '$oldname': $!\n";
}
1;
...
You can feed the "old" filenames (those to be copied) from a pipe or as an input file:
# find /path -type f -name "abc.log*" | ./mycopy
(or):
# ./mycopy file_of_list_of_files
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-25-2009 02:59 PM
тАО08-25-2009 02:59 PM
Re: Copying files for different instance names
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-25-2009 03:07 PM
тАО08-25-2009 03:07 PM
Re: Copying files for different instance names
> Is single command possible with the combination of awk or sed ?
How long a command line do you want? How obtuse do you want to make it? What will you do everytime you want to use it? Why do you ask for 'awk' or 'sed' --- you could manage parts of your objective in either since 'awk' has a 'system()' function and 'sed' can do regular expression backreferences but neither can do both like Perl.
HENCE, do you want a solution or do you want to tell us the only way you want your problem solved?
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-25-2009 04:02 PM
тАО08-25-2009 04:02 PM
Re: Copying files for different instance names
I was just exploring if it was possible and not rigid on a specific solutions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-25-2009 04:10 PM
тАО08-25-2009 04:10 PM
Re: Copying files for different instance names
> Sorry James for misunderstanding!! I am interested in solutions.
I was just exploring if it was possible and not rigid on a specific solutions.
Then please accept my apology for mis-reading your query! Sometimes of late, you never know. I am a believer in TMTOWTDI and I should have taken your question in that context.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-25-2009 05:26 PM
тАО08-25-2009 05:26 PM
Re: Copying files for different instance names
Your help and contribution has benefitted me lot on this forum.
This forum keeps HP-UX ahead of others.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-25-2009 08:22 PM
тАО08-25-2009 08:22 PM
Re: Copying files for different instance names
cp /logs/venus/abc.log-08222009 /tmp/abc.log-08222009-venus
For this exact pattern you can use:
for file in /logs/*/abc.log*; do
new_file=$(echo $file | sed -e 's:/logs/\([^/]*\)/\(.*\):\2-\1:')
cp $file /tmp/$new_file
done