10-17-2009
removing first 7 characters of directory names
Hi, I'm relatively new to unix, and would like to change the following files in a particular directory. The files have names like:
M10_90_Phcn402_3F.ab1
M10_94_Sput402_3F.ab1
M11_92_Abrg402_3R.ab1
M10_91_Cdel402_3F.ab1
M11_90_Phcn402_3R.ab1
M12_84_Sput402_3R.ab1
M10_93_Ehdr402_3F.ab1
M11_71_Cdel402_3R.ab1
M12_95_Epic402_3R.ab1
I would like to remove the first 7 characters of each file. For instance, in the first one, I would like M10_90_ to be removed, so the file name becomes Phcn402_3F.ab1
I have been playing with:
for x in M1*;do mv $x ${x/nnn/};done
I'm not sure what the correct expression is to remove the first 7 characters (not sure what to put in place of "nnn"). Is there a fast way to do this, or is there a different way to do this, maybe with "rename"?
Thanks
Last edited by euspilapteryx; 10-17-2009 at 07:31 PM..
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi,
I have searched the forum on how to mass replace the file names. We are doing the migration and I am trying to accomplish a task where I have to replace all UNIX scripts in a particular directory that start with bdw to fdm...
For example: bdw0110137.sh should be fdm0110137.sh
Keep the... (4 Replies)
Discussion started by: madhunk
4 Replies
2. UNIX for Dummies Questions & Answers
hai,
I am new to Unix, I have a requirement to display owner name , directory or sub directory name, who's owner name is not equal to "oasitqtc".
(here "oasitqtc" is the owner of the directory or sub directory.)
i have a command (below) which will display all folders and sub folders, but i... (6 Replies)
Discussion started by: gagan4599
6 Replies
3. Red Hat
Hello,
when i start to take backup following error generate please share solution for this problem i am very thankful to you.
$ tar -czvf orahome.tar.gz /testhome/TEST/PROD/orahome/
tar: Removing leading `/' from member names
O.S 4.5 Red Hat
Thanks,
Umair (1 Reply)
Discussion started by: umair
1 Replies
4. Shell Programming and Scripting
Hi All,
I have some 50,000 HTML files in a directory. The problem is; some HTML files are duplicate versions that is wget crawled them two times and gave them file names by appending 1, 2, 3 etc after each crawl. For example, if the file index.html has been crawled several times, it has been... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies
5. UNIX for Dummies Questions & Answers
I am trying to loop through folders and extract the name of the lowest level subfolder
I was running the script below, it returns
/bb/bin/prd/newyork
/bb/bin/prd/london
/bb/bin/prd/tokyo
I really want
newyork
london
tokyo
I couldn't find a standard variable for the lowest level... (1 Reply)
Discussion started by: personalt
1 Replies
6. UNIX for Dummies Questions & Answers
I have this piece of code
printf '%s\n' $pth*.msf | tr ' ' '\n' | sort -t '-' -k7 -k6r \
| awk -F- '{c=($6$7!=p&&FNR!=1)?ORS:"";p=$6$7}{printf("%c%s\n",c,$0)}'
When I run it I get
/home/chrisd/tatsh/branches/terr0.50/darwin/n02-z30-dsr65-terr0.50-dc0.002-8x6drw-csq.msf... (8 Replies)
Discussion started by: kristinu
8 Replies
7. Shell Programming and Scripting
got it figured out :) (1 Reply)
Discussion started by: sHockz
1 Replies
8. Shell Programming and Scripting
I'm trying to move a large folder to an external drive but some files have these weird chars that the external drive won't accept.
Does anyone know any command of any bash script that will look through a given folder and remove any weird chars? (4 Replies)
Discussion started by: Joktaa
4 Replies
9. UNIX for Dummies Questions & Answers
I found a closed thread that helped quite a bit. I tried adding the URL, but I can't because I don't have enough points... ?
Modifying the syntax to remove ! ~
find . -type f -name '*~\!]*' |
while IFS= read -r; do
mv -- "$REPLY" "${REPLY//~\!]}";
done
These messages are... (2 Replies)
Discussion started by: rabidphilbrick
2 Replies
10. Shell Programming and Scripting
Hello -
I was looking to write a simple script trying to rename sub-directories chopping off the last n characters.
For example:
In /home/myname/dir there are three sub-directories: directory1_1, directory2_2, and directory3_3.
Is there a simple script to chop off the last... (4 Replies)
Discussion started by: twckfa16
4 Replies
LEARN ABOUT ULTRIX
unpack
pack(1) General Commands Manual pack(1)
Name
pack, pcat, unpack - compress and expand files
Syntax
pack [ - ] [ -f ] name...
pcat name...
unpack name...
Description
The command stores the specified files in a compressed form. Wherever possible (and useful), each input file name is replaced by a packed
file name.z with the same access modes, access and modified dates, and owner as those of name. The -f option forces packing of name.
Using this option you can cause an entire directory to be packed even if some of the files cannot benefit from it. If is successful, name
is removed. Packed files can be restored to their original form using or
The command uses Huffman (minimum redundancy) codes on a byte-by-byte basis. If a hyphen (-) is used as an argument, an internal flag is
set that causes the number of times each byte is used, its relative frequency, and the code for the byte to be printed on the standard out-
put. Additional occurrences of a hyphen (-) in place of name causes the internal flag to be set and reset.
The amount of compression obtained depends on the size of the input file and the character frequency distribution. Because a decoding tree
forms the first part of each .z file, it is usually not worthwhile to pack files smaller than three blocks, unless the character frequency
distribution is skewed, which may occur with printer plots or pictures.
Typically, text files are reduced to 60-75% of their original size. Load modules, which use a larger character set and have a more uniform
distribution of characters, show little compression. The packed versions are about 90% of the original size.
The command returns a value that is the number of files that it failed to compress.
No packing occurs if one of the following is true:
o The file appears packed.
o The file name exceeds 12 characters.
o The file has links.
o The file is a directory.
o The file cannot be opened.
o No disk storage blocks can be saved by packing.
o A file called already exists.
o The .z file cannot be created.
o An I/O error occurred during processing.
The last segment of the file name must not exceed 12 characters to allow space for the appended .z extension. Directories cannot be com-
pressed.
The command does for packed files what does for ordinary files, except that can not be used as a filter. The specified files are unpacked
and written to the standard output. Thus, to view a packed file named name.z use:
pcat name.z
or just:
pcat name
To make an unpacked copy, say nnn, of a packed file named (without destroying name.z) use the command:
pcat name >nnn
The command returns the number of files it was unable to unpack. Failure may occur if:
the file name (exclusive of the .z) has more than 12 characters;
the file cannot be opened;
the file does not appear to be the output of pack.
The command expands files created by For each file name specified in the command, a search is made for a file called name.z (or just name,
if name ends in .z). If this file appears to be a packed file, it is replaced by its expanded version. The new file has the .z suffix
stripped from its name, and has the same access modes, access and modification dates, and owner as those of the packed file.
The command returns a value that is the number of files it was unable to unpack. Failure occurs for the same reasons that it occurs in as
well as for the following:
a file with the unpacked name already exists;
if the unpacked file cannot be created.
This command is present only for compatibility. In general, the command runs faster and gives better compression.
See Also
cat(1), compress(1)
pack(1)