Sponsored Content
Operating Systems Linux Red Hat How to pass value of pwd as variable in SED to replace variable in a script file Post 302613641 by cielle on Tuesday 27th of March 2012 02:08:04 PM
Old 03-27-2012
Hi Corona688, thank you for your prompt reply.

I have tested and tried to edit my script with yout advice.. but still unable to get the value of PWD to replace my copy of shell script.

I have 2 shell script, a.sh and b.sh.

a.sh will make a copy of b.sh at /etc/init.d and will replace the "$PWD" keyword in the copy of b.sh.

Below is the edited code for my scripts:

a.sh

Code:
current_dir="$PWD"
echo $current_dir

cp $current_dir/b.sh /etc/init.d/copyOfb.sh
sed -i 's/$PWD/"$current_dir"/g' /etc/init.d/copyOfb.sh

b.sh
Code:
current_dir="$PWD"
echo $current_dir

when i execute the a.sh... the keyword PWD in copy of b.sh is replaced with the string "$current_dir"
and eventually i have this
current_dir=""$current_dir""
in my copyOf b.sh....


I tried to manipulate the quotes.. but still unable to get the thing right...

please advise again...
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Pass variable to sed?

Hi there. If variables are named inside of a ksh script, how is it possible to pass these to sed? The affected portion of my script goes something like this: A=`cut -d. -f1 $FILE` B=`cut -d. -f2 $FILE` C=`cut -d. -f3 $FILE` sed 's/1111/$A/g;s/2222/$B/g;s/3333/$C/g' file > anotherfile ... (2 Replies)
Discussion started by: kristy
2 Replies

2. Shell Programming and Scripting

pass a variable to sed p in a loop?

Hi, Thanks for looking,,,, (kornshell) tmp3 is a list of line numbers I want to print the lines from my list code: while read j do echo $j #works fine echo $filename #works fine #sed "'$jp'" "$filename" ... (7 Replies)
Discussion started by: JohnMario
7 Replies

3. Shell Programming and Scripting

Pass perl variable to sed

Hello, I'd like to pass a variable to a sed command in a perl script. The script is like this : #!/usr/bin/perl -w $newline="new"; system q(sed '/insert/ i\ '$newline <sed1.txt >sed2.txt); But the interpretor wouldn't recognize $newline, it inserts a "\n" instead. I've also... (4 Replies)
Discussion started by: hi_ryo
4 Replies

4. Shell Programming and Scripting

pass variable to sed like in awk (-v switch)

hi all is possible to pass shell (bash) variable to sed like it is in awk? example: awk script is storred in awk.awk file and I am passing variable called var to this file. $ cat awk.awk {if ($5==var) print $0} so it works when i issue $ bash_var=24 $ ls -l | awk -v... (1 Reply)
Discussion started by: wakatana
1 Replies

5. Shell Programming and Scripting

using file-and-replace sed command with the use of a variable?

Ok, so, let's say I have the variable $GMAILID....How can I use it with sed command so to replace a string in a file? e.g.: sed -i 's/$GMAILID/test@gmail.com/' /home/$USER/Desktop/sendmail (4 Replies)
Discussion started by: hakermania
4 Replies

6. Shell Programming and Scripting

Replace value of a variable in a file through script using sed

Hi, I am trying to replace the value of a variable in a file through another script. Example: Filename : abc.txt contents: a=10 b=20 c=30 Need to change the value of, say, b - Tried using the following: sed "s/${b}/15/g" abc.txt Have tried various forms of sed (with single quotes,... (4 Replies)
Discussion started by: rituparna_gupta
4 Replies

7. Shell Programming and Scripting

How to replace a string with a variable in a file using sed?

I have a file having some text like: PATH_ABC=/user/myLocation I have to replace "/user/myLocation" with a session variable say, $REPLACE_PATH, where $REPLACE_PATH=/user/myReplaceLocation The following sed command is not working. It is writing PATH_ABC=$REPLACE_PATH in the file ... (2 Replies)
Discussion started by: SKhan
2 Replies

8. Shell Programming and Scripting

ksh script trying to pass a variable to edit a file

I'm trying to create a ksh script that will ask the user for the port number. $PORT1 is the variable I want to use that will contain whatever numbers the user inputs. The script would edit ports.txt file, search and delete "./serv 110.1.0.1.$PORT1 200;=3" . So if the user types 50243 then the... (5 Replies)
Discussion started by: seekryts15
5 Replies

9. Shell Programming and Scripting

Shell script to pass the config file lines as variable on the respective called function on a script

I want to make a config file which contain all the paths. i want to read the config file line by line and pass as an argument on my below function. Replace all the path with reading config path line by line and pass in respective functions. how can i achieve that? Kindly guide. ... (6 Replies)
Discussion started by: sadique.manzar
6 Replies

10. UNIX for Beginners Questions & Answers

Awk/sed to replace variable in file

Hi All I have one file with multiple lines in it, each line has static text and some variable enclosed in <<filename>> as well. e.g. as below 123, <<file1.txt>> this is my name, I stay at <<city.txt>> Thanks for visiting 348384y, this is my name <<fileabc.txt>>, I stay at near the mall of... (8 Replies)
Discussion started by: reldb
8 Replies
OPANNOTATE(1)						      General Commands Manual						     OPANNOTATE(1)

NAME
opannotate - produce source or assembly annotated with profile data SYNOPSIS
opannotate [ options ] [profile specification] DESCRIPTION
opannotate outputs annotated source and/or assembly from profile data of an OProfile session. See oprofile(1) for how to write profile specifications. OPTIONS
--assembly / -a Output annotated assembly. The binary file to be annotated does not need full debugging information to use this option, but symbol information is required. Without symbol information, opannotate will silently refuse to annotate the binary. If this option is com- bined with --source, then mixed source / assembly annotations are output. --demangle / -D none|smart|normal none: no demangling. normal: use default demangler (default) smart: use pattern-matching to make C++ symbol demangling more read- able. --exclude-dependent / -x Do not include application-specific images for libraries, kernel modules and the kernel. This option only makes sense if the profile session used --separate. --exclude-file [files] Exclude all files in the given comma-separated list of glob patterns. --exclude-symbols / -e [symbols] Exclude all the symbols in the given comma-separated list. --help / -? / --usage Show help message. --image-path / -p [paths] Comma-separated list of additional paths to search for binaries. This is needed to find modules in kernels 2.6 and upwards. --root / -R [path] A path to a filesystem to search for additional binaries. --include-file [files] Only include files in the given comma-separated list of glob patterns. --merge / -m [lib,cpu,tid,tgid,unitmask,all] Merge any profiles separated in a --separate session. --include-symbols / -i [symbols] Only include symbols in the given comma-separated list. --objdump-params [params] Pass the given parameters as extra values when calling objdump. If more than one option is to be passed to objdump, the parameters must be enclosed in a quoted string. An example of where this option is useful is when your toolchain does not automatically recognize instructions that are specific to your processor. For example, on IBM POWER7/RHEL 6, objdump must be told that a binary file may have POWER7-specific instructions. The opannotate option to show the POWER7-specific instructions is: --objdump-params=-Mpower7 The opannotate option to show the POWER7-specific instructions, the source code (--source) and the line numbers (-l) would be: --objdump-params="-Mpower7 -l --source" --output-dir / -o [dir] Output directory. This makes opannotate output one annotated file for each source file. This option can't be used in conjunction with --assembly. --search-dirs / -d [paths] Comma-separated list of paths to search for source files. You may need to use this option when the debug information for an image contains relative paths. --base-dirs / -b [paths] Comma-separated list of paths to strip from debug source files, prior to looking for them in --search-dirs. --session-dir=dir_path Use sample database from the specified directory dir_path instead of the default locations. If --session-dir is not specified, then opannotate will search for samples in <current_dir>/oprofile_data first. If that directory does not exist, the standard session-dir of /var/lib/oprofile is used. --source / -s Output annotated source. This requires debugging information to be available for the binaries. --threshold / -t [percentage] Only output data for symbols that have more than the given percentage of total samples. --verbose / -V [options] Give verbose debugging output. --version / -v Show version. ENVIRONMENT
No special environment variables are recognised by opannotate. FILES
<current_dir>/oprofile_data/samples Or /var/lib/oprofile/samples/ The location of the generated sample files. VERSION
This man page is current for oprofile-0.9.9. SEE ALSO
/usr/share/doc/oprofile/, oprofile(1) 4th Berkeley Distribution Tue 10 June 2014 OPANNOTATE(1)
All times are GMT -4. The time now is 10:51 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy