renaming a compressed file to filename without .Z


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers renaming a compressed file to filename without .Z
# 1  
Old 08-15-2005
Java renaming a compressed file to filename without .Z

In a shell script I would like to use a compressed file name, i.e. with suffix of .Z, as a file input $1. After the file in uncompressed, I would like to use the file name without the .Z . How do I do this?

Thank you.
# 2  
Old 08-15-2005
This will return file: basename file.Z .Z

This is how I would do it:
Code:
#!/bin/bash

if [ "$1" = "" ]
   then echo "Usage: $0 file.Z"
        exit 1
fi

uncompress $1
mv `basename $1 .Z` newfilename

# 3  
Old 08-15-2005
Error renaming a compressed filename without .Z

I guess that I wasn't specific enough.

the script -
uncompress $1
mv `basename $1 .Z` newfilename

requires input of a file name. What I tried to say was
where $1 = basename.Z
after compression this becomes basename
how do I rename $1 or save to another variable the filename = basename
by itself?
# 4  
Old 08-15-2005
Quote:
Originally Posted by bruceps
I guess that I wasn't specific enough.

the script -
uncompress $1
mv `basename $1 .Z` newfilename

requires input of a file name. What I tried to say was
where $1 = basename.Z
after compression this becomes basename
how do I rename $1 or save to another variable the filename = basename
by itself?
not sure if I understand what you're trying to explain, but....
After the decompression '$1' will still have the value of 'basename.Z' and the decompressed file will be named 'basename'.

Can you try to explain again, pls!
# 5  
Old 08-15-2005
Do you want to replace the value of $1 without the .Z?

That would be: 1=`basename $1 .Z`
# 6  
Old 08-16-2005
Quote:
Originally Posted by 98_1LE
Do you want to replace the value of $1 without the .Z?

That would be: 1=`basename $1 .Z`
I dont think you can replace the value's of the postitional parameter $1 like you have mentioned. They are a read-only parameter.

One of the ways to change the value is to use shift. But it is of no good in this particular post.

Vino
# 7  
Old 08-16-2005
EDIT: You are right. I learned something else tonight Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Renaming files by appending string from within file to filename

Greetings. I am working in a Linux environment and am trying to figure out a way to rename files in a directory by appending a unique strings that appears within a certain area in those files. I have gotten as far as identifying what that particular unique string is with a command like the... (10 Replies)
Discussion started by: HLee1981
10 Replies

2. Shell Programming and Scripting

Renaming multiple files at once (discarding suffix of the filename after a character)

Hi, I have a lot of files similar to the below order. I want to rename all the files .discrading the time stamp/numbers after cnf. Existing files id_info_20130405.cnf_20130801 in_info_20130405.cnf_20130891 iz_info_20130405.cnf_20130821 in_info_20130405.cnf_20130818... (2 Replies)
Discussion started by: saravanapandi
2 Replies

3. Shell Programming and Scripting

Search compressed files with awk and get FILENAME

I have many compressed files I want to search using awk and want to print some file contents along with the filename it came from on each output record (I simplified awk command). Here are the results with the files uncompressed: awk '{print FILENAME, $0}' test*.txt test1.txt from test1... (3 Replies)
Discussion started by: mjf
3 Replies

4. Shell Programming and Scripting

Renaming file that has multiple numbers as filename

Hi I have a file with filename as "partition-setup-and-ipl.vtcmd.76217657132.9721536798" Now i need to move this file as "partition-setup-and-ipl.vtcmd.76217657132.9721536798_org" i tried with # ls | grep -E "partition-setup-and-ipl.vtcmd.+"... (2 Replies)
Discussion started by: Priya Amaresh
2 Replies

5. Shell Programming and Scripting

Renaming a filename

Hi friends , i want to change the filename as below filename=ABC_HYND_JDHD_20130125120345.txt expected output : ABC_HYND_JDHD_20130125.txt i have tried using awk but not able to procedd futher. i am trying to do the above in single commad. echo... (3 Replies)
Discussion started by: i150371485
3 Replies

6. Shell Programming and Scripting

Renaming the filename

Hi, I have several files with name b1.root, b2.root b3.root I want to rename the "b" to "bkg", so finally is should be: bkg1.root bkg2.root bkg3.root I used command: rename s/b/bsig/ b*root Somehow it is working at some place and not working in other folder. I do not have any idea... (3 Replies)
Discussion started by: nrjrasaxena
3 Replies

7. Shell Programming and Scripting

BASH Batch renaming insert additional zero into filename

Hi all, Wondering how this could be accomplished........ a directory contains sequentially numbered files from fw01 to fw999. How would I insert an additional zero so that the directory lists these files in a proper manner? (i.e. all double digit files from fw01 to fw99 would become... (3 Replies)
Discussion started by: putter1900
3 Replies

8. Shell Programming and Scripting

compressed file

i have a file 4d7a94d0.bbb.1292 when i do file 4d7a94d0.bbb.1292 the ouput is below 4d7a94d0.bbb.1292: gzip compressed data - deflate method and i run this command gunzip -c 4d7a94d0.bbb.1292 | awk '{gsub("\"","")}/I_ACCOUNT_ID/{print $2}' RS=":|;" FS="," i get... (3 Replies)
Discussion started by: blackzinga80
3 Replies

9. UNIX for Dummies Questions & Answers

compressed file

I compressed a file by using gzip command gzip <<xx>> filename changed to xx.gz How to view this xx.gz file. Any idea. Thanks in advance. (7 Replies)
Discussion started by: venkatesht
7 Replies

10. UNIX for Dummies Questions & Answers

Renaming files to have date/time in filename

I have a program that will export my data to a single file, but it assigns a file name that is overridden every time I run the program. I need to change the file name to have a sequential number in the filename. How do I rename a file so that the filename contains the system date and time. I want... (5 Replies)
Discussion started by: wayneb
5 Replies
Login or Register to Ask a Question