LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-09-2012, 07:27 PM   #16
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

Rep: Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325

Have you considered the printf cmd?
http://ss64.com/bash/printf.html
 
Old 07-09-2012, 08:09 PM   #17
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
What have you tried?

Here's a quick guess at a crude solution:
Assume that we're always dealing with just numbers, and there is always at least one digit and not more than four.
So, the allowable filenames include:
9
23
456
2345
09
034
0231
0002

I put this in a file called "numpad"

First, use this to add 3 zeros to each one:
Code:
[mherring@herring_desk ~]$ sed 's/.*/000&/' numpad
0009
00023
000456
0002345
00009
000034
0000231
0000002
now, we use sed to truncate to the last 4 characters:
Code:
[mherring@herring_desk ~]$ sed 's/.*/000&/' numpad | sed -r 's/.*(.{4})$/\1/'
0009
0023
0456
2345
0009
0034
0231
0002
As I said, crude. Wait awhile and someone will have something a bit more elegant.
 
Old 07-09-2012, 08:10 PM   #18
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
OOOOOOps---the better answer was already there----but it's good to know that SED will do it....
 
Old 07-09-2012, 08:26 PM   #19
rosehosting.com
Member
 
Registered: Jun 2012
Posts: 222

Rep: Reputation: 62
Using printf

Code:
for i in *; do
  j=$(printf %04d $i)
  [ $i != $j ] && mv $i $j
done
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Script to delete aligned single-character columns with no field separator? kmkocot Programming 15 04-22-2010 11:45 AM
how to delete nth character in a text file? xiawinter Linux - Software 3 05-13-2008 11:50 AM
Can VI Do This?? Delete before a character in text - Maybe advanced. tbeehler Linux - Software 9 05-07-2007 06:02 PM
vi editor - how to delete a character in each row of a column? flipwhy Linux - Newbie 6 01-22-2007 03:12 PM
vi command to find and delete all lines beginning with a character geomatt Linux - Software 8 12-20-2004 04:30 AM


All times are GMT -5. The time now is 03:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration