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
OPREPORT(1)						      General Commands Manual						       OPREPORT(1)

NAME
opreport - produce symbol or binary image summaries SYNOPSIS
opreport [ options ] [profile specification] DESCRIPTION
opreport outputs binary image summaries, or per-symbol data, from OProfile profiling sessions. See oprofile(1) for how to write profile specifications. OPTIONS
--accumulated / -a Accumulate sample and percentage counts in the symbol list. --debug-info / -g Show source file and line for each symbol. --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. --callgraph / -c Show call graph information if available. --details / -d Show per-instruction details for all selected symbols. --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-symbols / -e [symbols] Exclude all the symbols in the given comma-separated list. --global-percent / -% Make all percentages relative to the whole profile. --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-symbols / -i [symbols] Only include symbols in the given comma-separated list. --long-filenames / -f Output full paths instead of basenames. --merge / -m [lib,cpu,tid,tgid,unitmask,all] Merge any profiles separated in a --separate session. --no-header / -n Don't output a header detailing profiling parameters. --output-file / -o [file] Output to the given file instead of stdout. --reverse-sort / -r Reverse the sort from the default. --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 opreport 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. --show-address / -w Show each symbol's VMA address. --sort / -s [vma,sample,symbol,debug,image] Sort the list of symbols by, respectively, symbol address, number of samples, symbol name, debug filename and line number, binary image filename. --symbols / -l List per-symbol information instead of a binary image summary. Usually, the total of all per-symbols samples for a given binary image equals the summary count for the binary image (shown by run- ning opreport with no options). However, it's possible for some sample addresses to fall outside the range of any symbols for a given binary image. In such cases, the total number of per-symbols samples for the binary image may be less than the summary count for the image. Running opreport with the --verbose=debug option will display an informational message when this difference is detected. This difference is typically very small and can be ignored. --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. --xml / -X Generate XML output. ENVIRONMENT
No special environment variables are recognized by opreport. 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 OPREPORT(1)
All times are GMT -4. The time now is 02:21 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy