Sponsored Content
Top Forums Shell Programming and Scripting Find filenames with three digits and add zeros to make five digits Post 302591184 by agama on Wednesday 18th of January 2012 07:59:23 PM
Old 01-18-2012
Probably lots of ways to do this. You can pipe the output of a find command through this small awk which will generate the mv commands.

Code:
find . -type f | awk '{ o = $0; split( $NF, a, "." ); $(NF)=sprintf( "%05d.%s", a[1], a[2] ); printf( "mv \"%s\" \"%s\"\n", o, $0 ); }'

You can then pipe the output through your favorite shell to actually execute the moves (verify that they look good, and no undesired file is being affected. It's generic so it will handle any suffix (.jpg, .png, etc.). It does assume that in the bag of words in the middle, the last word and the number are separated by a space.
This User Gave Thanks to agama For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to cut last 10 digits off

Hi I'm new to this. I need to cut off the last 10 digits from a line. I've used awk {'print $4'} filename.txt | cut -c 32-42 but this does not guarantee only the last 10 characters. Please help. Thanks. Sara (4 Replies)
Discussion started by: psarava
4 Replies

2. Shell Programming and Scripting

Write a shell program to find the sum of alternate digits in a given 5-digit number

Hi Can any one please post the answer for the above program.................. (4 Replies)
Discussion started by: banta
4 Replies

3. Shell Programming and Scripting

Formatting digits

I want to check the argument in KSH. If the user type in the prompt 'find 3' it will format 3 to 003 to match the data in the text file. Same as with 10 to 010. Always begins with 0. eg. >find 3 Output: 003 >find 30 Output: 030 (7 Replies)
Discussion started by: harry0013
7 Replies

4. Shell Programming and Scripting

find the last digits of a string

print out 201 in following string, Please note the chars before 201 are random, no fixed format. ua07app201 (20 Replies)
Discussion started by: honglus
20 Replies

5. Shell Programming and Scripting

help: single digits inflated to 2 digits

Hi Folks Probably an easy one here but how do I get a sequence to get used as mentioned. For example in the following I want to automatically create files that have a 2 digit number at the end of their names: m@pyhead:~$ for x in $(seq 00 10); do touch file_$x; done m@pyhead:~$ ls file*... (2 Replies)
Discussion started by: amadain
2 Replies

6. Shell Programming and Scripting

Use match() in nawk to find digits in number

Hi, I just need to check whether number of digits in a phone number is 10 or not. If I am not wrong regex will be: {9} I have to use this inside nawk as this is a small portion of a big program. nawk ' BEGIN { RS="";FS=";"; regex="{9}"; } { for (i=1;i<=NF;i++) { if... (6 Replies)
Discussion started by: shekhar2010us
6 Replies

7. Shell Programming and Scripting

find sequence of 13 digits in file

I need to extract all sequences of thirteen digits in a file, e.g. 4384976350232, and at the same time not extract sequences with 14 or more digits. How do I do that using sed, awk or something built into bash? (8 Replies)
Discussion started by: locoroco
8 Replies

8. Shell Programming and Scripting

Regex find first 5-7 occurrences of a set of digits within a string

Using these strings as an example: <a onclick="doShowCHys=1;ShowWindowN(0,'/daman/man.php?asv4=145148&amp;playTogether=True',960,540,943437);return false;" title=""> <a onclick="doShowCHys=1;ShowWindowN(0,'/daman/man.php?asv4=1451486&amp;playTogether=True',960,540,94343);return false;" title=""> <a... (12 Replies)
Discussion started by: metallica1973
12 Replies

9. Shell Programming and Scripting

Find number of digits in a word

HI, Can you tell me how to find the number of digits in a word. $cat data.txt +123456ad 87645768 Output should be 6 8 (5 Replies)
Discussion started by: ashwin3086
5 Replies

10. UNIX for Beginners Questions & Answers

sed / awk script to delete the two digits from first 3 digits

Hi All , I am having an input file as stated below 5728 U_TOP_LOGIC/U_CM0P/core/u_cortexm0plus/u_top/u_sys/u_core/r03_q_reg_20_/Q 011 611 U_TOP_LOGIC/U_CM0P/core/u_cortexm0plus/u_top/u_sys/u_core/r04_q_reg_20_/Q 011 3486... (4 Replies)
Discussion started by: kshitij
4 Replies
el(1)							      General Commands Manual							     el(1)

NAME
el -- program to make a tuned shell-command for Oneliner SYNOPSIS
el [-acdfhioxV] [--command cmd] [--args n] [--format fmt] [--execute] [--inpipe buf] [--outpipe buf] [--serial] [--help] [--ver- sion] [--debug] DESCRIPTION
This manual page documents briefly the el command. This manual page was written for the Debian distribution because the original program does not have a manual page. Instead, it has docu- mentation in the GNU Info format; see below. el is a program that You can make a tuned shell-command for Oneliner with. This command can send S-exp to Emacs, and this can make Emacs evaluate it, too. In other words, you can execute Emacs's function from shell-commands. And you can make Emacs work in closer cooperation with your favorite shell-commands. OPTIONS
These programs follow the usual GNU command line syntax, with long options starting with two dashes (`-'). A summary of options is included below. For a complete description, see the Info files. -c cmd --command cmd cmd means a function of Elisp. Command line arguments and data from stdin means arguments of cmd. If you specify the only -c switch, el output one S-exp by one line of stdin. --a n --args n Specifies the maximum number of arguments of a Elisp function with -c switch. -f fmt --format fmt Allows you to use format string of printf for making a S-exp. -x --execute Requests to Oneliner to evaluate the S-exp to use *Oneliner auto-eval* buffer. -i buf --inpipe buf Gets input from pipe-buffer. You can specify a number of pipe-buffer, too. -o buf --outpipe buf Puts output to pipe-buffer. You can specify a number of pipe-buffer, too. -s --serial Makes el to serialize multiple lines to one line. -h --help Display help message. -V --version Display version identifiers. -d --debug Enable debugging state. SEE ALSO
The programs are documented fully by Oneliner(Shell-mode hooks for Oneliners) available via the Info system. AUTHOR
This manual page was written by OHURA Makoto <ohura@debian.org> for the Debian system (but may be used by others). Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License, Version 2 any later version published by the Free Software Foundation. On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL. el(1)
All times are GMT -4. The time now is 11:15 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy