- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- How to truncate a file name when copying it
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
тАО04-06-2005 04:59 AM
тАО04-06-2005 04:59 AM
We would like to rename them to the same name minus the HHMMSS.txt. There may be multiple files, the value of HHMMSS will be the time they were created on the remote server. Any suggestions?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2005 05:07 AM
тАО04-06-2005 05:07 AM
Re: How to truncate a file name when copying it
either use awk or cut or sed to parse out the garbage....
Rgds...Geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2005 05:12 AM
тАО04-06-2005 05:12 AM
SolutionFor example:
# touch aap_noot_mies_20050404123456.txt
# touch aap_noot_teun_20050404654321.txt
# ls aap*
aap_noot_mies_20050404123456.txt aap_noot_teun_20050404654321.txt
# ls aap* | perl -ne 'chop; rename $_ , $1 if (/(^.*_\d{8})\d{6}(.txt)/)'
# ls aap*
aap_noot_mies_20050404 aap_noot_teun_20050404
The (.txt) makes sure you work on .txt files only allows you to glue that back if you like: rename $_ $1.$2
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2005 05:15 AM
тАО04-06-2005 05:15 AM
Re: How to truncate a file name when copying it
chars_to_get=$((${all_char)-6))
new_file_ext=$(echo "file_name"|awk -F _ '{print $4}'|awk -F . '{print $1}'|cut -c1-$)chars_to_get}.txt
Anil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2005 05:26 AM
тАО04-06-2005 05:26 AM
Re: How to truncate a file name when copying it
I have realized that I mis-stated something, we want to also drop the <3rdpart> of the file when renaming it, I'm trying to decipher the instructions to figure out how to make this work, but I must admit I just don't speak the lingo!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2005 05:37 AM
тАО04-06-2005 05:37 AM
Re: How to truncate a file name when copying it
# mv old_name `echo old_name | awk -F_ '{print $1"_"$2".txt"}`
If you want to do this for all the *.txt files in current
directory, then
for old_name in *.txt
do
mv $old_name `echo $old_name | awk -F_ '{print $1"_"$2".txt"}'`
done
Just put the above script in a file and execute it.
- Biswajit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2005 05:40 AM
тАО04-06-2005 05:40 AM
Re: How to truncate a file name when copying it
one single line (my previous was formatted
automatically after posting).
- Biswajit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2005 06:10 AM
тАО04-06-2005 06:10 AM
Re: How to truncate a file name when copying it
oldIFS="$IFS"
IFS="${IFS}_"
print $filename | read p1 p2 p3 p4
IFS="$oldIFS"
yearMonth="${p4%??????????" #12 ?'s
newFileName="${p1}_${p2}_$yearMonth"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2005 09:24 AM
тАО04-06-2005 09:24 AM
Re: How to truncate a file name when copying it
In my perl example that rew request would become:
ls aap* | perl -ne 'chop; rename $_ , $1.$2 if (/(^.\w+_\w+)_\w+(_\d{8})\d{6}(.txt)/)'
The regular expression does the work.
It remember 3 elements describe between parens in $1, $2 and $3
(^.\w+_\w+_) = start-of-line plus some-word plus underscore plus some-word --> $1
_\w+ = underscore plus some-word... matched but forgotten
(_\d{8}) = underscore plus exactly 8 decimals --> $2
\d{6} = exactly 6 decimals... match but forgotten
(.txt) = anychar (".") plus "txt"... remembered but unused --> $3
Enjoy.
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2005 09:52 AM
тАО04-06-2005 09:52 AM
Re: How to truncate a file name when copying it
Regards,
June