how to modify the value of the variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to modify the value of the variable
# 1  
Old 06-12-2008
how to modify the value of the variable

Hi
I have a variable which holds full path to the file, for example
z=/bb/data3/f4222pdb.dta.new
I need to remove the extension .new so it would look like
z=/bb/data3/f4222pdb.dta
Is there a command to do this? This variable is used in the "for" loop later. I am in ksh. Thanks a lot -A
# 2  
Old 06-12-2008
Code:
echo $z
/bb/data3/f4222pdb.dta.new

z=${z%.+([a-z])}

echo $z
/bb/data3/f4222pdb.dta

# 3  
Old 06-12-2008
Hammer & Screwdriver on possible solution

Code:
z=/bb/data3/f4222pdb.dta.new
> echo $z
/bb/data3/f4222pdb.dta.new

> echo $z | cut -d"." -f1-2
/bb/data3/f4222pdb.dta

or, doing the replacement in one command line
Code:
z=/bb/data3/f4222pdb.dta.new
z=$(echo $z | cut -d"." -f1-2)
> echo $z
/bb/data3/f4222pdb.dta

# 4  
Old 06-13-2008
An even simplier solution.
Code:
$ z=${z%.new}
$ print $z
/bb/data3/f4222pdb.dta

# 5  
Old 06-13-2008
newz=${z%%.new}

mv newz z
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Please modify solution

Hi Please check my code,here awk -vLIT="$line" '$0 ~ LIT { print LIT,"Found in ",FILENAME; }' $f it is not checking for small alphabets.can u pls modify my code #!/bin/ksh for f in /tmp/satemp/* do cat /tmp/sa/tt.txt| while read line do awk -vLIT="$line" '$0 ~ LIT { print LIT,"Found in... (3 Replies)
Discussion started by: coolboy98699
3 Replies

2. UNIX for Dummies Questions & Answers

How to modify an output?

I have a list XPAR XPAR XPAR , XPAR , , XPAR ,1, XPAR 196 XPAR 95 XPAR 95,77 This has space and tabs on the second row. I would like it to look like XPAR 1, 196, 95, 77 But I always get the below because of the spaces above. , , ,1, 196 95 95,77 I use... (9 Replies)
Discussion started by: priyanka.premra
9 Replies

3. Shell Programming and Scripting

Modify a file by another file: add new line and variable after string is found

hello, I have problem with writing/adjusting a shell script. I searched forum and unfortunately couldn't write scipt based on the information I found. I never wtire such so it's hard for me and I do need to modify one script immediately. case looks like: 1. 'file' that needs to be modified... (3 Replies)
Discussion started by: bipbip
3 Replies

4. Shell Programming and Scripting

Modify line with dynamic variable in awk

Hi, I'm guessing this is probably relatively straight forward to do in awk, but I just can't get my head round it! I have a log file of the following format: 3:03:35 (lmgrd) TIMESTAMP 10/14/2011 3:20:41 (MLM) IN: "MATLAB" user1@host1.private.dns.zone 3:21:05 (MLM) IN: "MATLAB"... (2 Replies)
Discussion started by: chrissycc
2 Replies

5. UNIX for Dummies Questions & Answers

grep and modify

if input1 has an expression nouse covert allcolumns in to hashes except 6th column. ex: abc100 has no use in 3rd row and 4th row and became hashes. BUT if input1 1st column keys-1st row has no words in 3rd column (ex: def200 (key) and 1st row has no words in 3rd column (no x/x or y/y or others)... (2 Replies)
Discussion started by: ruby_sgp
2 Replies

6. Shell Programming and Scripting

Modify a file

Hi all Can anyone suggest me a good solution ? My requirement is as follows I have a plain text file similar to this... sending data to 0003345234 here is the output... ,.......... ........... ....... sending data to 00033452ab here is the output... ,.......... ........... .... (5 Replies)
Discussion started by: ./hari.sh
5 Replies

7. Shell Programming and Scripting

How to modify the variable

I have a directory name stored in a variable. Does anyone have a piece of code which checks if this stored directory name ends up with the "/" and if it is missing adds it to the same variable. for example I might have A=/bb/data or A=/bb/data/ which needs to be A=/bb/data/ for sure thanks... (5 Replies)
Discussion started by: aoussenko
5 Replies

8. Shell Programming and Scripting

Request to modify script to list multiple parameters for V_fieldid variable

I am posting a script below which essentially excutes the following functions in the described order. 1) From a source directory pools together three files generated by system logs for each user session, tar's these files and archives them as a log set in a destination directory and these... (0 Replies)
Discussion started by: Sammy
0 Replies

9. UNIX for Advanced & Expert Users

Modify files

Hi everybody, I have a certine file with lots of number, Which I want to add a " in the begging and at the and of each line. Could anyone tell me how can I do it? Cheers (7 Replies)
Discussion started by: amgo
7 Replies

10. Shell Programming and Scripting

modify a file

I'm a new member of the forum, I had this new generate file since I use 'grep' and 'awk', what I want to do is get rid off the all 0s before the numbers, is there any one who could help me to figure it out? Thanks a lot! yun 0000000029 000q7472 2002/03/01 0000000030 000q7472 2002/03/01 ... (2 Replies)
Discussion started by: yxiao
2 Replies
Login or Register to Ask a Question