Sponsored Content
Top Forums Shell Programming and Scripting grep string & a few lines after Post 302247902 by arunrao_oradba on Thursday 16th of October 2008 03:34:55 PM
Old 10-16-2008
sed does not work through shell script

hi gurus,
I am trying to use sed to get certain line after a requested line.
the sed works if i run manually but if i put it through shell it does not work.

Any help will be greatly appreciated.

$ cat bt.ksh
ttt=`sed -n '/LAST_UPDATED_DATE/,$p' extractedmessage.out|head -2|tail -1`

cat testing.cfg|while read extractdata
do
whattext=`echo $extractdata|awk -F"||" {'print $1'}`
howmanylines=`echo $extractdata|awk -F"||" {'print $2'}`
echo $whattext $howmanylines

sed -n '/${whattext}/,$p' extractedmessage.out|head -${howmanylines}|tail -1 >bt.out
echo $tttt
done

< ibmrxcpi-rptdb1 : nwp1 : oracle : /users/oracle/arao >
$ cat testing.cfg
LAST_UPDATED_DATE||2
LAST_UPDATED_BY||2
< ibmrxcpi-rptdb1 : nwp1 : oracle : /users/oracle/arao >
$ cat extractedmessage.out
object: RXP_PATIENT
is tag null: Y
command_type: UPDATE
old(1): PATIENT_ID
3380910
old(2): CREATED_DATE
20-JAN-99
old(3): CREATED_BY
RXP_DM_P001
old(4): LAST_UPDATED_DATE
06-APR-08
old(5): LAST_UPDATED_BY
RXP_DM_P012
< ibmrxcpi-rptdb1 : nwp1 : oracle : /users/oracle/arao >
$ ksh -x bt.ksh
+ + sed -n /LAST_UPDATED_DATE/,$p extractedmessage.out
+ head -2
+ tail -1
ttt=06-APR-08
+ cat testing.cfg
+ read extractdata
+ + echo LAST_UPDATED_DATE||2
+ awk -F|| {print $1}
whattext=LAST_UPDATED_DATE
+ + echo LAST_UPDATED_DATE||2
+ awk -F|| {print $2}
howmanylines=2
+ echo LAST_UPDATED_DATE 2
LAST_UPDATED_DATE 2
+ sed -n /${whattext}/,$p extractedmessage.out
+ head -2
+ tail -1
+ 1> bt.out
+ echo

+ read extractdata
+ + echo LAST_UPDATED_BY||2
+ awk -F|| {print $1}
whattext=LAST_UPDATED_BY
+ + echo LAST_UPDATED_BY||2
+ awk -F|| {print $2}
howmanylines=2
+ echo LAST_UPDATED_BY 2
LAST_UPDATED_BY 2
+ sed -n /${whattext}/,$p extractedmessage.out
+ head -2
+ tail -1
+ 1> bt.out
+ echo

+ read extractdata
< ibmrxcpi-rptdb1 : nwp1 : oracle : /users/oracle/arao >
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

grep string & next n lines

need help on this. let say i hv 1 file contains as below: STRING Description bla bla bla Description yada yada yada Data bla bla Data yada yada how do i want to display n lines after the string? thanks in advance! (8 Replies)
Discussion started by: ashterix
8 Replies

2. Shell Programming and Scripting

Grep string but also it will show the next 5 lines

Hi experts, I want to grep a number 9366109380 from a file but it will also show me the next 5 lines. Below is the example- when i grep 989366109380, i can also see the next 5 lines. Line 1. <fullOperation>MAKE:NUMBER:9366109380:PPAY2;</fullOperation> Line 2.... (10 Replies)
Discussion started by: thepurple
10 Replies

3. Shell Programming and Scripting

Like grep -v for a string over 2 lines? Sed?

Hi, I have a log file that I need to monitor as it's being written to, and I want to exclude certain strings from the output. At the moment I'm using ... tail -f LogFileName_`date +%d`.log | egrep -v "First String To Exclude | 2nd string | 3rd string" ...which works OK - but now I need to... (1 Reply)
Discussion started by: jake657
1 Replies

4. Shell Programming and Scripting

Print lines between two lines after grep for a text string

I have several very large file that are extracts from Oracle tables. These files are formatted in XML type syntax with multiple entries like: <ROW> some information more information </ROW> I want to grep for some words, then print all lines between <ROW> AND </ROW>. Can this be done with AWK?... (7 Replies)
Discussion started by: jbruce
7 Replies

5. Shell Programming and Scripting

Find a string using grep & print the line above or below that.

Hi All, Please tell me how can I Find a string using grep & print the line above or below that in solaris? Please share as I am unable to use grep -A or grep -B as it is not working on Solaris. (10 Replies)
Discussion started by: Zaib
10 Replies

6. Shell Programming and Scripting

Grep a string from input file and delete next three lines including the line contains string in xml

Hi, 1_strings file contains $ cat 1_strings /home/$USER/Src /home/Valid /home/Review$ cat myxml <projected value="some string" path="/home/$USER/Src"> <input 1/> <estimate value/> <somestring/> </projected> <few more lines > <projected value="some string" path="/home/$USER/check">... (4 Replies)
Discussion started by: greet_sed
4 Replies

7. Shell Programming and Scripting

Grep couple of consecutive lines if each lines contains certain string

Hello, I want to extract from a file like : 20120530025502914 | REQUEST | whatever 20120530025502968 | RESPONSE | whatever 20120530025502985 | RESPONSE | whatever 20120530025502996 | REQUEST | whatever 20120530025503013 | REQUEST | whatever 20120530025503045 | RESPONSE | whatever I want... (14 Replies)
Discussion started by: black_fender
14 Replies

8. Shell Programming and Scripting

Grep last two lines, calc & adding comments

....... 06/09/2013|12:00:00 PM|3|26112|40|44032|27419.7|6 1 0 93 |6|1|0|93 06/09/2013|12:30:00 PM|3|26112|40|44032|27491|11 4 0 85 |11|4|0|85 I have "sysperf.out" file containing the lines above. What I like to have on the output is: Node: prod1db ===> this is the hostname Date:... (7 Replies)
Discussion started by: Daniel Gate
7 Replies

9. Shell Programming and Scripting

Grep a string and count following lines starting with another string

I have a large dataset with following structure; C 0001 Carbon D SAR001 methane D SAR002 ethane D SAR003 propane D SAR004 butane D SAR005 pentane C 0002 Hydrogen C 0003 Nitrogen C 0004 Oxygen D SAR011 ozone D SAR012 super oxide C 0005 Sulphur D SAR013... (3 Replies)
Discussion started by: Syeda Sumayya
3 Replies

10. Shell Programming and Scripting

Grep three consecutive lines if each lines contains certain string

say we have : 2914 | REQUEST | whatever 2914 | RESPONSE | whatever 2914 | SUCCESS | whatever 2985 | RESPONSE | whatever 2986 | REQUEST | whatever 2990 | REQUEST | whatever 2985 | RESPONSE | whatever 2996 | REQUEST | whatever 2010 | SUCCESS | whatever 2013 | REQUEST | whatever 2013 |... (7 Replies)
Discussion started by: Saumitra Pandey
7 Replies
DDB(8)							    BSD System Manager's Manual 						    DDB(8)

NAME
ddb -- configure DDB kernel debugger properties SYNOPSIS
ddb capture [-M -core] [-N -system] print ddb capture [-M -core] [-N -system] status ddb script scriptname ddb script scriptname=script ddb scripts ddb unscript scriptname ddb pathname DESCRIPTION
The ddb utility configures certain aspects of the ddb(4) kernel debugger from user space that are not configured at compile-time or easily via sysctl(8) MIB entries. To ease configuration, commands can be put in a file which is processed using ddb as shown in the last synopsis line. An absolute pathname must be used. The file will be read line by line and applied as arguments to the ddb utility. Whitespace at the beginning of lines will be ignored as will lines where the first non-whitespace character is '#'. OUTPUT CAPTURE
The ddb utility can be used to extract the contents of the ddb(4) output capture buffer of the current live kernel, or from the crash dump of a kernel on disk. The following debugger commands are available from the command line: capture [-M core] [-N system] print Print the current contents of the ddb(4) output capture buffer. capture [-M core] [-N system] status Print the current status of the ddb(4) output capture buffer. SCRIPTING
The ddb utility can be used to configure aspects of ddb(4) scripting from user space; scripting support is described in more detail in ddb(4). Each of the debugger commands is available from the command line: script scriptname Print the script named scriptname. script scriptname=script Define a script named scriptname. As many scripts contain characters interpreted in special ways by the shell, it is advisable to enclose script in quotes. scripts List currently defined scripts. unscript scriptname Delete the script named scriptname. EXIT STATUS
The ddb utility exits 0 on success, and >0 if an error occurs. EXAMPLES
The following example defines a script that will execute when the kernel debugger is entered as a result of a break signal: ddb script kdb.enter.break="show pcpu; bt" The following example will delete the script: ddb unscript kdb.enter.break For further examples, see the ddb(4) and textdump(4) manual pages. SEE ALSO
ddb(4), textdump(4), sysctl(8) HISTORY
The ddb utility first appeared in FreeBSD 7.1. AUTHORS
Robert N M Watson BUGS
Ideally, ddb would not exist, as all pertinent aspects of ddb(4) could be configured directly via sysctl(8). BSD
December 24, 2008 BSD
All times are GMT -4. The time now is 02:44 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy