Sponsored Content
Top Forums UNIX for Dummies Questions & Answers How to truncate thousands of file names Post 302330441 by jim mcnamara on Wednesday 1st of July 2009 09:23:53 AM
Old 07-01-2009
Usually if there are characters in a filename that are metacharacters - they mean something to the shell - you can surround the filename with double quotes or single quotes (tic) and copy the file or rename it. To remove the last 4 chars in the filename means you have to feed it to the mv command. Which the same as feeding it to a cp command

Try something like this to rename the files:
Code:
#!/bin/bash
ls ./maildir |
while read filename
do
   len=${#filename}
   len=$(( $len - 4 ))
   printf "mv '%s'  '%s'" "${filename}"  "${filename:0:$len}"
done > tmp.sh
chmod +x tmp.sh
tmp.sh

TEST this first.
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to truncate a large (8 GB) file

Hello, I need to truncate a large file without deleting and touching it again. i tried the below commands but no use because of the huge file size cat <<! > errors and echo > errors Could someone please help. Thanks, Sateesh (1 Reply)
Discussion started by: kotasateesh
1 Replies

2. Shell Programming and Scripting

Truncate File contain

I have one file which first line is blank and second line has some data. $cat filename output: 30-MAY-07 I want to store 30-MAY-07 value in one variable. for that I wrote var="`head -2 filename`" It will give that result but I want to truncate the first line which is blank. plz help. (2 Replies)
Discussion started by: rinku
2 Replies

3. Solaris

script for Gzip thousands of file

Hi experts, I have thousands of file (data file and Gziped file) in same directory like below-- bash-2.05$ pwd /home/mmc bash-2.05$ file PP023149200709270546 TT023149200709270546: gzip compressed data - deflate method bash-2.05$ file PP027443200711242320 TT027443200711242320: ... (10 Replies)
Discussion started by: thepurple
10 Replies

4. UNIX for Dummies Questions & Answers

Truncate last <n> characters from a file

I am trying to concatenate 2 files, but before concatenation, I would like to strip off the final character from the first file. The final character is a form feed (ascii 012 / hex 0C) and there will be an unknown number of these characters in the file. It is only the very last one which I want... (1 Reply)
Discussion started by: Gwailo88
1 Replies

5. Shell Programming and Scripting

Truncate extra contents from file

Hi all, i have a file and i want that after 6th slash "/" in each line of the file the contents gets truncated. Can anyone tell me how to do that !! thanks in advance One more thing how can i change the size of output buffer of console, as i had very long output and its not... (2 Replies)
Discussion started by: glamo_2312
2 Replies

6. Shell Programming and Scripting

Searching for file names in a directory while ignoring certain file names

Sun Solaris Unix Question Haven't been able to find any solution for this situation. Let's just say the file names listed below exist in a directory. I want the find command to find all files in this directory but at the same time I want to eliminate certain file names or files with certain... (2 Replies)
Discussion started by: 2reperry
2 Replies

7. Shell Programming and Scripting

Truncate file name to 40 characters

Hello all. I would like to make a script (or two shell scripts) that will do the following. I need the maximum file name and directory name to be 38 characters long. As well, if shortening the file name ends up making all of the files in that directory have the same name, then I would like... (9 Replies)
Discussion started by: marcozd
9 Replies

8. UNIX for Dummies Questions & Answers

recover the truncate file

hi All, how to recover the truncate file in unix. Thanks!:wall: (2 Replies)
Discussion started by: krbala1985
2 Replies

9. Shell Programming and Scripting

Exclude certain file names while selectingData files coming in different names in a file name called

Data files coming in different names in a file name called process.txt. 1. shipments_yyyymmdd.gz 2 Order_yyyymmdd.gz 3. Invoice_yyyymmdd.gz 4. globalorder_yyyymmdd.gz The process needs to discard all the below files and only process two of the 4 file names available ... (1 Reply)
Discussion started by: dsravanam
1 Replies
gdcmgendir(1)							       GDCM							     gdcmgendir(1)

NAME
gdcmgendir - Tool to generate a DICOMDIR file from a File-Set. SYNOPSIS
gdcmgendir [options] file-in file-out DESCRIPTION
PARAMETERS
file-in DICOM input filename file-out DICOM output filename options Parameters options -i --input DICOM filename or directory -o --output DICOM filename or directory -r --recursive recursive. --descriptor descriptor. --root-uid Root UID. general options -h --help print this help text and exit -v --version print version information and exit -V --verbose verbose mode (warning+error). -W --warning warning mode, print warning information -E --error error mode, print error information -D --debug debug mode, print debug information environment variable GDCM_ROOT_UID Root UID Typical usage NOTE
One may have to run some preliminary steps in order to get gdcmgendir to generate the DICOMDIR file. Namely two steps: o Batch renaming of the DICOM filename into something compatible with ISO 9660 filename convention o Convert all DICOM file into the Explicit VR Little Endian Uncompressed (1.2.840.10008.1.2.1) Step 1. can be solved in a numerous way. Eg. on UNIX environment this could either be solved using the mkisofs command line tool. filename should not contains any extension since the VR CS does not allow for the '.' character. Only upper case, digit 0-9, the space ' ' and the underscore '_' character are valid in VR CS, with a maximum of 8 bytes. Another simple tool that can be handy is 'rename' in conjunction with 'basename'. Step 2. can simply be achieved using the gdcmconv command line tool: $ for i in `ls IMG*`; do gdcmconv --raw --force $i /tmp/out/$i; done SEE ALSO
gdcmconv(1), gdcmanon(1), rename(1) COPYRIGHT
Copyright (c) 2006-2011 Mathieu Malaterre Version 2.2.0 Tue Feb 5 2013 gdcmgendir(1)
All times are GMT -4. The time now is 02:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy