How to partially replace variable value?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to partially replace variable value?
# 1  
Old 06-11-2008
How to partially replace variable value?

I have variable $2 whose value is expdp_SDW_MSTR_VMDB.par
I want to replace three characters from right (par) with (log)

Input --> expdp_SDW_MSTR_VMDB.par
Output --> expdp_SDW_MSTR_VMDB.log

Thanks
Deep
# 2  
Old 06-11-2008
Code:
var=expdp_SDW_MSTR_VMDB.par
newname=${var%%par}log

# 3  
Old 06-12-2008
Hammer & Screwdriver Another approach

Note the use of the $ with the par$ in the sed command; this means to grab the text at the end of a line. Hence, the command did not change the par earlier in the text string.

Code:
> var=expdp_par_SDW_MSTR_VMDB.par
> var2=$(echo $var | sed "s/par$/log/")
> echo $var2
expdp_par_SDW_MSTR_VMDB.log

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Sftp transfers file partially

Hi ALL, I have a shell script using except : #!/bin/bash HOST=abc.com USER=abc PASSWORD=123 SOURCE_FILE=file1.zip TARGET_DIR=/A/B/C /usr/bin/expect <<- EOF spawn /usr/bin/sftp $USER@$HOST expect "password:" send "$PASSWORD\r" expect "sftp>" send "cd patch1\n" ... (11 Replies)
Discussion started by: Asad
11 Replies

2. UNIX for Dummies Questions & Answers

Partially match and rank question

Hi I am processing some files but have difficulty to deal with this one, hope someone can help me,Thank you in advance. I have a file 1 like this file 1:aa|M30369.1| mfe: -15.1 kc b|BX930090.1| mfe: -10.2 kc GOOD mfe: -20.3 kc BAD3.2 mfe: -25.4 kc I also have a file 2 like this file2:GOOD... (8 Replies)
Discussion started by: yuejian
8 Replies

3. Shell Programming and Scripting

Command / script to partially rename file

Hi I have numerous files names product_host_result_B1000842.txt product_host_result_B1000847.txt product_host_result_C1000842.txt product_host_result_C1000848.txt etc. I need them renamed so that the 'product_host_result' becomes 'output_product_host' but the rest of the filename is... (6 Replies)
Discussion started by: Grueben
6 Replies

4. UNIX for Dummies Questions & Answers

Script partially executes??

Hi All, I am calling a shell script from another shell script, however, it only executes part of it (the echo commands only). What could be some causes for that? For example: ShellScriptA.sh: ... ... ... . ShellScriptB.sh ShellScriptB.sh contents: echo date echo... (7 Replies)
Discussion started by: DBnixUser
7 Replies

5. Red Hat

How to pass value of pwd as variable in SED to replace variable in a script file

Hi all, Hereby wish to have your advise for below: Main concept is I intend to get current directory of my script file. This script file will be copied to /etc/init.d. A string in this copy will be replaced with current directory value. Below is original script file: ... (6 Replies)
Discussion started by: cielle
6 Replies

6. Shell Programming and Scripting

How to output the partially equals

Hello i have 2 files: a.out 10.1.1.1 james.franco 10.1.1.3 google.gol 10.1.1.14 yahoo.bol b.out 10.1.1.1 10.1.1.3 10.1.1.45 I need to see an output just with: 10.1.1.1 james.franco 10.1.1.3 google.gol Thankz in advance!! (2 Replies)
Discussion started by: danielldf
2 Replies

7. Shell Programming and Scripting

Is it possible to partially clear the terminal?

The clear command specifically says it can only clear the entire terminal display. There are no arguments. So I'm wondering if there are any work arounds. Carriage return does not work for this as it only moves the cursor to the beginning of the line we're on. And obviously NL only goes down. If... (1 Reply)
Discussion started by: FunkyLich
1 Replies

8. AIX

logical volume partially mirrored

Hello I have a question On one of my aix servers if I type lsvg -l rootvg I got this 0516-1147 : Warning - logical volume waslv may be partially mirrored. waslv jfs2 277 477 3 open/syncd /usr/WebSphere If I type lslv -m waslv |more waslv:/usr/WebSphere... (4 Replies)
Discussion started by: lo-lp-kl
4 Replies

9. Shell Programming and Scripting

How to replace variable inside the variable

hi sir, i need your help for this script inside /rnmucdr/ednms05/ken/xMNBDF045_Script.sql content variable like this select * from invoice where bill_date=$BILLDATE and startNum=$STARTPARTNNUM and total_partn=$TOTALPARTN if i just paste this replace with the $SCRIPT it works great,if... (31 Replies)
Discussion started by: mani_um
31 Replies

10. Shell Programming and Scripting

Replace variable with a user defined variable

I have a file that has a list of entries in a column x z z z x y z The column can have any length and any number of any strings. I need to replace each unique string with a user defined number. I can filter the unique entries out using awk '{if (NF==5) print $2}' file | uniq | nl >... (1 Reply)
Discussion started by: ce124
1 Replies
Login or Register to Ask a Question