Help others have a topic

xiaoxiao2021-03-06  19

Help others have a topic

Author: Badcoffee

Email: blog.oliver@gmail.com

BLOG: http://blog.9cbs.net/yayong

December 2004

Title: SHELL programming, implementation:

/ TMP path has 800 files, the file name is: filename_yyyyymmdd_ serial number (from 001 to

999) .dat, for example: filename_20040108_089.dat

Now I want to rename these files, the format of the new file name is: FileName_Today (current date) _ serial number

(From 500, start from 001 after the 999) .dat,

For example: change filename_20040108_089.dat to filename_20041222_589.dat, pay attention to new text

The order of the serial number of the name needs to be consistent with the original, that is, the ordering process is made.

program:

#! / usr / bin / bash

Dest_file_part2 = "_` Date ' % Y% M% D'`_"

EXT_NAME = ". DAT"

SRC_FILE_LIST = `FIND / TMP -NAME" * _ * _ * $ ext_name "-print`

For each in $ src_file_list; do

DEST_FILE_PART1 = `Echo $ Each | awk -f" _ "'{print $ 1}'`

Old_num = `Echo $ Each | awk -f" _ "'{print $ 3}' | awk -f". '{Print $ 1}' `

DEST_FILE_PART3 = `EXPR $ OLD_NUM 500`

[$ Dest_file_part3 -gt 999] && dest_file_part3 = `expr $ old_num - 499`

&& dest_file_part3 = `Printf% 03D $ dest_file_part3`

DEST_FILE = $ dest_file_part1 $ dest_file_part2 $ dest_file_part3 $ ext_name

Echo "MV $ Each To $ Dest_file"

MV $ Each $ DEST_FILE

DONE

转载请注明原文地址:https://www.9cbs.com/read-77244.html

New Post(0)