Vi quick substitution commands


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Vi quick substitution commands
# 1  
Old 05-15-2014
Vi quick substitution commands

I have a script that has quite a lot of these types of entries:

Code:
hello=$(who am i)
good=$(blahblah)


what i want to do is replace the
Code:
$(

and the
Code:
)

with
Code:
``

so that they look like this:


Code:
hello=`who am i`
good=`blahblah`


I tried this:

Code:
:%s~=$(&&)$~=`&&`$~g

but of course it failed miserably. can anyone help me fix this?

im having to do this because the script needs to run on SunOS but solaris doesnt seem to like the
Code:
$()

# 2  
Old 05-15-2014
after vi .. you have to press 'Ecs' then ':' then
try
Code:
%s/$(/`/g

and
Code:
%s/)/`/g

Not sure why it is not running at your end.
But i have Solaris and i tried to run
Code:
hello=$(who am i)
good=$(uname -a)
echo $hello
echo $good

output
Code:
[Makarand] # ./sky.sh
mak pts/4 May 13 13:29 (10.214.28.125)
SunOS Makarand 5.8 Generic_117350-61 sun4u sparc SUNW,Sun-Fire-V440


Last edited by Makarand Dodmis; 05-15-2014 at 01:11 PM..
# 3  
Old 05-15-2014
Quote:
Originally Posted by Makarand Dodmis
after vi .. you have to press 'Ecs' then ':' then
try
Code:
%s/$(/`/g

and
Code:
%s/)/`/g



i actually tried this already. unfortunately, this script actually has several variations of $(......)

i need to be able to only make the changes to back ticks if and only if the line contains:

Code:
=$(

and ends with a
Code:
)

# 4  
Old 05-15-2014
Quote:
Originally Posted by SkySmart
i actually tried this already. unfortunately, this script actually has several variations of $(......)

i need to be able to only make the changes to back ticks if and only if the line contains:

Code:
=$(

and ends with a
Code:
)

SunOS could care less about $(cmd) versus `cmd`. However, /bin/sh on Solaris systems is an old Bourne shell that doesn't recognize the $(cmd) form of command substitution. If you can change your script to use /usr/xpg4/bin/sh, /usr/xpg6/bin/sh, /bin/ksh, or /bin/bash instead of /bin/sh as its interpreter, you won't need to change to back ticks.

If you can't, use the following command in vi to change the command substitutions following an equals sign that end at the end of a line in the file you're editing:
Code:
:g/=\$(\(.*\))$/s//=`\1`/

This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using commands inside sed substitution

Dear Friends, Please let me know how to use the date command inside the substitution flag replacement string. echo "01 Jan 2003:11:00:06 +0100" | sed 's/\(.*\)/`date -d \1 "+%Y%m%d%H%M%S"`/' I want to supply \1 string to Here mention below as part of replacement string, date -d <Here>... (5 Replies)
Discussion started by: tamil.pamaran
5 Replies

2. UNIX for Dummies Questions & Answers

quick way to get earlier commands?

I used to use a linux system that would allow me to bring up previously-used commands by typing the first (or more) letters of a previous command and then hitting the tab key. It was incredibly useful. Now I've switched to using a mac and it doesn't work. Is there an analog to this for macs? ... (3 Replies)
Discussion started by: ac2011
3 Replies

3. AIX

HACMP: difference between 'cl' commands and 'cli' commands

Hi all, I'm new in this forum. I'm looking for the difference between the HACMP commands with the prefix "cl" and "cli". The first type are under /usr/es/sbin/cluster/sbin directory and the second are under /usr/es/sbin/cluster/cspoc directory. I know that the first are called HACMP for AIX... (0 Replies)
Discussion started by: peppix
0 Replies

4. Shell Programming and Scripting

ksh command substitution not executing block commands

We have a function defined in a ksh script that gets called repeatedly and concurrently by background jobs called from within the same shell script file to run PL/SQL commands against an Oracle database. The function is below: runPLSQL() { ORACLE_SID=${1} procName=${2} #... (7 Replies)
Discussion started by: rjgst5
7 Replies

5. UNIX for Dummies Questions & Answers

Quick help with UNIX commands (pipes and filters)

Hey all, I need a command line that creates a new file named whatever, say stuff.txt in the current working directory which contains the number of directories in the current working directory, followed by the number of empty files in the current working directory, followed by the name of the... (2 Replies)
Discussion started by: corpsegrinder
2 Replies

6. Shell Programming and Scripting

Difference between "Command substitution" and "Process substitution"

Hi, What is the actual difference between these two? Why the following code works for process substitution and fails for command substitution? while IFS= read -r line; do echo $line; done < <(cat file)executes successfully and display the contents of the file But, while IFS='\n' read -r... (3 Replies)
Discussion started by: royalibrahim
3 Replies

7. Shell Programming and Scripting

Can BASH execute commands on a remote server when the commands are embedded in shell

I want to log into a remote server transfer over a new config and then backup the existing config, replace with the new config. I am not sure if I can do this with BASH scripting. I have set up password less login by adding my public key to authorized_keys file, it works. I am a little... (1 Reply)
Discussion started by: bash_in_my_head
1 Replies

8. Solaris

Quick help!

Hi, iam trying to use lofiadm in solaris 5.10 but getting the following error.. bash-3.00# lofiadm -a /asmdisks/_file_disk1 lofiadm: /dev/lofictl: No such file or directory i dont see lofictl file in /dev .. i checked in other similar machines..i found this file..can i export this file from... (2 Replies)
Discussion started by: rags_s11
2 Replies

9. Programming

code that reads commands from the standard i/p and executes the commands

Hello all, i've written a small piece of code that will read commands from standard input and executes the commands. Its working fine and is execting the commands well. Accepting arguments too. e.g #mkdir <name of the directory> The problem is that its not letting me change the directory i.e... (4 Replies)
Discussion started by: Phrozen Smoke
4 Replies
Login or Register to Ask a Question