- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: simplest way to strip a character from a filen...
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
тАО02-21-2006 11:52 AM
тАО02-21-2006 11:52 AM
A sample file name is: x_0041257026_102110535974_2006-01-26T20:33:31.272Z.xml.28_00_05.Z
I wrote a clumbsy perl script to do it which is working but it soooo slooooow.
Is there a mean, easy and efficient way to do this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2006 12:18 PM
тАО02-21-2006 12:18 PM
Re: simplest way to strip a character from a filename
# perl -ple 's/\.//g;s/Z$/\.Z/'
As for example:
# echo "12.3\nabc_def.xyz\ndavid.Z"|perl -ple 's/\.//g;s/Z$/\.Z/'
(or):
# perl -ple 's/\.//g;s/Z$/\.Z/' fileofnames
This (crudely) preserves the ".Z" extension if present.
Regards!
...JRF...
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2006 12:19 PM
тАО02-21-2006 12:19 PM
Re: simplest way to strip a character from a filename
Looks like a time stamp...
Could do something like:
date '+%FT%H%M%S'
Rgds...Geoff
- Tags:
- date
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2006 12:23 PM
тАО02-21-2006 12:23 PM
Re: simplest way to strip a character from a filename
Try this awk construct...
# ls -1
cheers!
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2006 01:36 PM
тАО02-21-2006 01:36 PM
Re: simplest way to strip a character from a filename
for file in *
> do
> mv $file `echo $file | perl -ple 's/\://g'`
> done
Note that the char I wished to replace was a : and not a .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2006 02:02 PM
тАО02-21-2006 02:02 PM
Solutionls | while read FNAME
do
FNAME2=$(echo "${FNAME}" | tr -d ":")
if [[ "${FNAME}" != "${FNAME2}" && -n "${FNAME2}" ]]
then
if [[ -r "${FNAME2}" ]]
then
echo "${FNAME2} exists; can't mv" >&2
else
mv "${FNAME}" "${FNAME2}"
fi
fi
done
The idea is that we use tr -d to strip the ':'s from the filename. Next we check to see if the filenames are then diffirent and also that the filename still has a non-zero length. Next we make sure that the new filename does not already exist; if so, that file is skipped. Finally, after all the tests have passed we mv the old name to the new.
Note the "'s around each filename. Whitespace is perfectly legal (if dumb) in UNIX pathnames.
This should be a robust solution.
- Tags:
- tr
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2006 02:50 PM
тАО02-21-2006 02:50 PM
Re: simplest way to strip a character from a filename
> do
> mv $file `echo $file | perl -ple 's/\://g'`
> done
==
Simply as,
for file in `ls`
do
mv ${file} $(echo ${file} | perl -pe 's/://g')
done
--
Muthu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2006 02:53 PM
тАО02-21-2006 02:53 PM
Re: simplest way to strip a character from a filename
--
Muthu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2006 03:00 PM
тАО02-21-2006 03:00 PM
Re: simplest way to strip a character from a filename
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2006 03:11 PM
тАО02-21-2006 03:11 PM
Re: simplest way to strip a character from a filename
For processing large number of files, perl is the best way to go. It has proven ability when it comes to large number.
-Arun