- Community Home
- >
- Servers and Operating Systems
- >
- Legacy
- >
- Operating System - Tru64 Unix
- >
- Re: getting the latest file from list of files
Operating System - Tru64 Unix
1753559
Members
5752
Online
108796
Solutions
Forums
Categories
Company
Local Language
юдл
back
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
юдл
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- 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
тАО03-18-2009 06:22 AM
тАО03-18-2009 06:22 AM
getting the latest file from list of files
Hi,
I have a requirement as below ( OS: Hp Tru64 UNIX 5.1b): I have to get *_pos_pay.txt list of files and from the list I should get the latest file and cp it into *_pos_pay.txt_ but if the latest file is payroll_pos_pay.txt, I shouldn't copy it instead I have to get the next latest file and copy it as above.
My code is as below:
======================
file= ls -lat *pos_pay.txt | cut -c55-75 | head -2
file1= ls -lat *pos_pay.txt | cut -c55-75 | head -1
stampyyyymmdd=`date +"%Y%m%d"`
count=`ls $file |grep -c payroll_pos_pay.txt`
echo $count
if [[ ${count} > 0 ]]; then
sfile= $file | cut -c21-39
cp $sfile $sfile_$stampyyyymmdd
exit;
else
cp $file1 $file1$stampyyyymmdd
exit;
fi
==================================
The command - {sfile= $file | cut -c21-39}
is taking the contents of the file in $file but I am trying to get the original file name by using the above command and then use the variable sfile in the cp command. Please advise.
Thanks
Aish.
I have a requirement as below ( OS: Hp Tru64 UNIX 5.1b): I have to get *_pos_pay.txt list of files and from the list I should get the latest file and cp it into *_pos_pay.txt_
My code is as below:
======================
file= ls -lat *pos_pay.txt | cut -c55-75 | head -2
file1= ls -lat *pos_pay.txt | cut -c55-75 | head -1
stampyyyymmdd=`date +"%Y%m%d"`
count=`ls $file |grep -c payroll_pos_pay.txt`
echo $count
if [[ ${count} > 0 ]]; then
sfile= $file | cut -c21-39
cp $sfile $sfile_$stampyyyymmdd
exit;
else
cp $file1 $file1$stampyyyymmdd
exit;
fi
==================================
The command - {sfile= $file | cut -c21-39}
is taking the contents of the file in $file but I am trying to get the original file name by using the above command and then use the variable sfile in the cp command. Please advise.
Thanks
Aish.
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-18-2009 07:34 AM
тАО03-18-2009 07:34 AM
Re: getting the latest file from list of files
Because there's nothing Tru64-specific about
this, you might try asking in an HP-UX forum.
There seem to be more people there who like
to write scripts for other people.
this, you might try asking in an HP-UX forum.
There seem to be more people there who like
to write scripts for other people.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-18-2009 10:09 PM
тАО03-18-2009 10:09 PM
Re: getting the latest file from list of files
If you use a real shell and awk, you can make your script much simpler:
file1=$(ls -lat *pos_pay.txt | fgrep -v payroll_pos_pay.txt | \
head -1 | awk '{print $NF}')
stampyyyymmdd=$(date +"%Y%m%d")
cp $file1 $file1$stampyyyymmdd
You may want to check if $file1 is null.
file1=$(ls -lat *pos_pay.txt | fgrep -v payroll_pos_pay.txt | \
head -1 | awk '{print $NF}')
stampyyyymmdd=$(date +"%Y%m%d")
cp $file1 $file1$stampyyyymmdd
You may want to check if $file1 is null.
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP