Changing the file name to a different one using csh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Changing the file name to a different one using csh
# 1  
Old 11-29-2011
Changing the file name to a different one using csh

I have a file name

Code:
n10-z30-dsr65-ndelt1.00-varp0.08-16x12drw-csq-msf.ps

and I want to remove the varp info tag to get

Code:
n10-z30-dsr65-ndelt1.00-16x12drw-csq-msf.ps

Trying to use tr, but when I tried replacing varp with ooo I am getting the results below:

Code:
echo "n10-z30-dsr65-ndelt1.00-varp0.08-16x12drw-csq-msf.ps" | tr 'varp' 'ooo'

n10-z30-dso65-ndelt1.00-oooo0.08-16x12dow-csq-msf.os





---------- Post updated at 07:40 AM ---------- Previous update was at 07:34 AM ----------


############################################################################

Using
Code:
echo "n10-z30-dsr65-ndelt1.00-varp0.08-16x12drw-csq-msf.ps" | awk '{gsub(/varp/,""); print}'

gives me

Code:
n10-z30-dsr65-ndelt1.00-0.08-16x12drw-csq-msf.ps

The problem is that I also want to remove the number 0.08

I have to get

Code:
n10-z30-dsr65-ndelt1.00-16x12drw-csq-msf.ps

# 2  
Old 11-29-2011
tr replaces sets of single characters, not strings as such.

tr 'varp' 'abcd' replaces v with a, a with b, etc.

Use sed:
Code:
 ... | sed 's/varp/ooo/g'

or awk:
Code:
 ... | awk '{gsub ("varp","ooo"); print}'

EDIT:

Quote:
Originally Posted by kristinu
The problem is that I also want to remove the number 0.08
Assuming the field is delimited by dashes, try
Code:
 ... | sed 's/varp[^-]*-//g'


Last edited by CarloM; 11-29-2011 at 08:50 AM..
# 3  
Old 11-29-2011
Try this...
Code:
sh-3.1$ echo 'n10-z30-dsr65-ndelt1.00-varp0.08-16x12drw-csq-msf.ps' | sed 's/varp/ooo/;s/.08//'

Is .08 fixed?
--ahamed
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Changing the prompt in CSH

Need assistance in changing prompt . Trying to change prompt in csh,tcsh shell . Below are the commands i tried in .cshrc and sourcing this files. set prompt = "$user@`uname -n` : ${cwd}> " #above commands works for username and hostname but cwd doesnt change directories set... (16 Replies)
Discussion started by: ajayram_arya
16 Replies

2. Shell Programming and Scripting

Changing script from csh to bash

Hello Guys I have a script working fine on csh, but I would like to change it to bash, how I should change this command to be able to work as bash script. :wall: if ( $fsw > "0" ) then foreach swath ( `awk 'BEGIN {for (i='$fsw';i<='$lsw';i++) printf ("%s\n", i) }'` ) ## work to be done... (2 Replies)
Discussion started by: jiam912
2 Replies

3. Shell Programming and Scripting

Changing file extension in csh alias

I want to type only the filename of a gcc source that has ".syn" as an extension and copy it, changing the extension to ".c" so it can be compiled. I do it as follows: if (-e $1.syn) then /bin/cp $1.syn $1.c endif This works fine, but if I want to repeat the compilation by... (1 Reply)
Discussion started by: ygmwayne
1 Replies

4. Ubuntu

error LD: undefined variable while changing shell from bash to csh

Hi, i am a beginner in ubuntu. my default shell is bash. everytime i try to change the shell with command "csh", i get a message (probably an error message). after i get into c-shell, when i try to execute a c shellscript, then it showed the same message. any idea about what is this about or any... (1 Reply)
Discussion started by: Avinash Nayak
1 Replies

5. Shell Programming and Scripting

[Solved] Changing to upper case in csh

How can I change a string contained in a variable to upper case using csh ??? ---------- Post updated at 08:39 AM ---------- Previous update was at 08:29 AM ---------- I think I've got it, using tr has solved the problem set opt = ` echo $opt | tr "" "" ` (1 Reply)
Discussion started by: kristinu
1 Replies

6. Shell Programming and Scripting

Is there anyway for file renaming in csh

Hi, I have the files like in a directory. filerefcellhg1.txt filerefcellhg2.txt filerefcellhg3.txt filerefcellhg4.txt filerefcellhg5.txt filerefcellhg6.txt filedonotchange.txt filedonot Desired output: filerefhg1.txt filereflhg2.txt filerefhg3.txt filerefhg4.txt... (1 Reply)
Discussion started by: vasanth_vadalur
1 Replies

7. UNIX for Dummies Questions & Answers

How to Convert to CSH File

Hi Everyone, I have a body of code that I'd like to know how to convert to a csh file. In Unix, under a directory, I wish to ls into each of its subdirectories: In Unix prompt I type foreach i(*) foreach? ls $i foreach? end however, when I try to store this body of code in .csh: ... (2 Replies)
Discussion started by: tommms
2 Replies

8. Shell Programming and Scripting

csh failing to call an 2 embedded csh script

I have an extraordinary problem with a csh script.....(feel free to berate the use of this but I'm modifying an existing bunch of them) Anyway, I have a master csh script which in turn calls a second csh script. This second csh script is below. Within this second script are two compiled C++... (1 Reply)
Discussion started by: pollsizer
1 Replies

9. Shell Programming and Scripting

Sorting the Void File in CSH

First and foremost, this is not a homework for your information. I'm just new to using c-shell programming and I just wanted to make my life easier @ work. Say, the file contains the following: ID FILE NO. SL VP 1 1 22 33 1 2 ... (3 Replies)
Discussion started by: ilak1008
3 Replies

10. UNIX for Dummies Questions & Answers

how to zero a file using csh

Hi I have always used ksh in the past, but now am using csh. To zero a file using ksh, you simply > filename. What is the command to do the same using csh? Thanks in advance. (3 Replies)
Discussion started by: jodie
3 Replies
Login or Register to Ask a Question