Hi, i need help passing variables to sed using ksh.
My goal is to get particular data from log files.
first i put a mark to the log files.
echo "TEST_"`date + %m_%d_%Y_%T"` >markFile
this will produce a 'markFile' which contain text like this
TEST_06_01_2009_21:55:09
Why do you need a file? A variable is simpler:
Quote:
then i put the mark in the beginning and the end of a test on file.log
cat markFile>>file.log
Even if you do use a file, you don't need cat to read a single line:
Quote:
...
...Let the test run
...
cat markFile>>file.log
as a result the log file will look like this
some text 1...
some text 2...
TEST_06_01_2009_21:55:09
some text 3...
some text 4...
some text 5...
TEST_06_01_2009_21:55:09
some text 6...
some text 7...
some text 8...
now i need to take the lines between those marks
TEST_06_01_2009_21:55:09
some text 3...
some text 4...
some text 5...
TEST_06_01_2009_21:55:09
as i said i am using ksh
create a variable
mark=`cat markFile`
sed -n '/$mark/,/$mark/p' acu.log
the issue is in the sed... sed doesn't want to take the value of $mark. i think sed sees $mark as a command.
Variables are not expanded inside single quotes; sed sees $mark as literally that: a dollar sign followed by m-a-r-k.
Hi folks,
I'm looking for a solution to pass variables to a sed-command. I'm reading a lot of threats and also the q&a "How can I use a variable in sed?". None of these commands works. I'm using AIX 5.2.
I want to do the following:
NUMBER=` echo 38341` | sed -n '/$NUMBER/p'
an obtained... (3 Replies)
I'm trying to write a ksh script that uses awk, but I want to pass variables to awk. For example (not working):
if ];then
searchstr=$1
lsof -i | awk '{if($9~/SEARCHSTR/) print $2} SEARCHSTR=$searchstr'
else
echo "usage: $0 <search string>"
fi
I tried several options. Is it... (3 Replies)
I am trying to pass a regular expression variable from a simple script to sed
to remove entries from a text file
e.g.
a='aaaa bbbb cccc ...|...:'
then executing sed from the script
sed s'/"'$a"'//g <$FILE > $FILE"_"1
my output file is always the same as the input file !!
any... (5 Replies)
Hello ,
I have a script named testscript.sh
wherein I have two variables $var and $final (both of which contain a number)
I have a sed write function inside this script as follows:
sed '1,2 w somefile.txt' fromfile.txt
Now , in the above i want to pass $var and $final instead of... (2 Replies)
Hi Folks,
How can I make the following to work from a korn shell?
old="OLDSTRING"
new="NEWSTRING"
file="myfile.txt"
sed -n 's/$old/$new/gp' $file
Thanks in advance
rogers42 (3 Replies)
I need sed to add a "/>" to the end of a line that contains/starts with <meta.
current line is <meta name="keywords" content="kayword 1, kwyword2">
and should be <meta name="keywords" content="kayword 1, kwyword2 " />
i need something like this?
find . -name "*.html" -print0 | xargs... (6 Replies)
Hello I am hoping you can help.
I use ksh in Solaris9
I am trying to pass user imputed variables into SED but for some reason can only get SED to recognize one variable.
I have experimented with te below command with putting ' ' and " " in different places but I cant seem to get it to... (8 Replies)
Using ksh to call a function which has awk script embedded.
It parses a long two element list file, filled with text numbers (I want column 2, beginning no sooner than line 45, that's the only known thing) . It's unknown where to start or end the data collection, dynamic variables will be used. ... (1 Reply)
Hi everyone,
I've re-written some of our scripts to use more functions and I've run into a situation where passing a variable to a sed function does not work. My function is a one-liner sed command as follows:
function StringSub()
{
sed -i "${1}/${2}/${3}/${4}" ${5}
}
Where ${1} through... (4 Replies)
I'm reading a text file using a while loop but when I call a function from within this loop it exits that same iteration … even though there are many more lines in the file to be read.
I thought it was something to do with the IFS setting but it appears that a function call (when run... (3 Replies)
Discussion started by: user052009
3 Replies
LEARN ABOUT ULTRIX
prof
prof(5) File Formats Manual prof(5)Name
prof - profile within a function
Syntax
#define MARK
#include <prof.h>
void MARK (name)
Description
The symbol produces a mark called name that is treated the same as a function entry point. Execution of the mark increments the counter
for that mark, and the program-counter time spent is accounted to the preceding mark or to the function if a preceding mark is not within
the active function.
The name argument can be any combination of numbers or underscores. Each name in a single compilation must be unique, but can be the same
as any ordinary program symbol.
For marks to be effective, the symbol must be defined before the header file is included. This may be defined by a preprocessor directive
as in the synopsis, or by a command line argument. For example:
cc -p -DMARK foo.c
If is not defined, the statements may remain in the source files, but they will be ignored.
Examples
In the following example, marks are used to determine how much time is spent in each loop. Unless the example is compiled with defined on
the command line, the marks are ignored:
#include <prof.h>
foo( )
{
int i, j;
.
.
.
MARK(loop1);
for (i = 0; i < 2000; i++) {
. . .
}
MARK(loop2);
for (j = 0; j < 2000; j++) {
. . .
}
}
See Alsoprof(1), profil(2), monitor(3c)
RISC prof(5)