Sponsored Content
Top Forums Shell Programming and Scripting aix :grep to get lines before and after string Post 302634293 by PhAnT0M on Thursday 3rd of May 2012 07:08:03 AM
Old 05-03-2012
aix :grep to get lines before and after string

am using AIX and I have a string "There is no process to read data written to a pipe". I want to get the output 2 lines before and 4 lines after this string. The string is present like more than 100 times in the log and I want to output, the last result in the log with this string

I tried using :

Code:
nawk 'c-->0;$0~s{if(b)for(c=b+1;c>1;c--)print r[(NR-c+1)%b];print;c=a}b{r[NR%b]=$0}' b=2   a=4 s="There is no process to read data written to a pipe" File.log

The output from this command is that I am getting all the 100 plus results where the above string is present

The -A number -B number command is not working in AIX
 

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 & a few lines after

i need to grep a STRING_A & the next few lines after the STRING_A example file: STRING_A yada yada line 1 line 2 STRING_B yada yada line 1 line 2 line 3 STRING_A yada yada line 1 line 2 line 3 line 4 STRING_A yada yada line 1 line 2 line 3 line 4 (7 Replies)
Discussion started by: ashterix
7 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

AIX equivalent to GNU grep's -B and -A [print lines after or before matching lines]

Hi folks I am not allowed to install GNU grep on AIX. Here my code excerpt: grep_fatal () { /usr/sfw/bin/gegrep -B4 -A2 "FATAL|QUEUE|SIGHUP" } Howto the same on AIX based machine? from manual GNU grep ‘--after-context=num’ Print num lines of trailing context after... (4 Replies)
Discussion started by: slashdotweenie
4 Replies

5. 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

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 for the string and then print the next 4 lines

RHEL 5.8 I have a text file like below. I want to grep for a string and then print the next 4 lines including the line with the string I grepped for For eg: I want grep for the string HANS and then print the next 4 lines including HANS $ cat someText.txt JOHN NATIONALITY:... (7 Replies)
Discussion started by: omega3
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
shevek::process(3)					     Library Functions Manual						shevek::process(3)

NAME
shevek::process - Create a process, optionally connection its standard in- and output streams to the calling program. SYNOPSIS
#include <process.hh> Inherits shevek::refbase. Public Member Functions Glib::RefPtr< shevek::fd > in () The standard input pipe, if it was requested. Glib::RefPtr< shevek::fd > out () The standard output pipe, if it was requested. Glib::RefPtr< shevek::fd > err () The standard error pipe, if it was requested. pid_t pid () The process ID. ~process () The destructor. This kills the process if it was still running. Static Public Member Functions static Glib::RefPtr< process > create (std::string const &command, std::list< std::string > &argv, bool pipe_stdin=true, bool pipe_stdout=true, bool pipe_stderr=true) Create a process from a filename and an argument list. static Glib::RefPtr< process > create (std::string const &command, std::list< std::string > &argv, std::list< std::string > const &envp, bool pipe_stdin=true, bool pipe_stdout=true, bool pipe_stderr=true) Create a process from a filename, an argument list and an environment. static Glib::RefPtr< process > shell (std::string const &command, bool pipe_stdin=true, bool pipe_stdout=true, bool pipe_stderr=true, std::string const &sh='/bin/sh') Run a string with the shell. static std::string run (std::string const &command, std::string const &sh) Run a process and return its output. static Glib::RefPtr< process > create (std::string const &command, bool pipe_stdin=true, bool pipe_stdout=true, bool pipe_stderr=true) Create a process without arguments. static Glib::RefPtr< process > create (std::string const &command, std::string const &a1, bool pipe_stdin=true, bool pipe_stdout=true, bool pipe_stderr=true) Create a process with one argument. static Glib::RefPtr< process > create (std::string const &command, std::string const &a1, std::string const &a2, bool pipe_stdin=true, bool pipe_stdout=true, bool pipe_stderr=true) Create a process with two arguments. static Glib::RefPtr< process > create (std::string const &command, std::string const &a1, std::string const &a2, std::string const &a3, bool pipe_stdin=true, bool pipe_stdout=true, bool pipe_stderr=true) Create a process with three arguments. static Glib::RefPtr< process > create (std::string const &command, std::string const &a1, std::string const &a2, std::string const &a3, std::string const &a4, bool pipe_stdin=true, bool pipe_stdout=true, bool pipe_stderr=true) Create a process with four arguments. static Glib::RefPtr< process > create (std::string const &command, std::string const &a1, std::string const &a2, std::string const &a3, std::string const &a4, std::string const &a5, bool pipe_stdin=true, bool pipe_stdout=true, bool pipe_stderr=true) Create a process with five arguments. static Glib::RefPtr< process > create (std::string const &command, std::string const &a1, std::string const &a2, std::string const &a3, std::string const &a4, std::string const &a5, std::string const &a6, bool pipe_stdin=true, bool pipe_stdout=true, bool pipe_stderr=true) Create a process with six arguments. static Glib::RefPtr< process > create (std::string const &command, std::string const &a1, std::string const &a2, std::string const &a3, std::string const &a4, std::string const &a5, std::string const &a6, std::string const &a7, bool pipe_stdin=true, bool pipe_stdout=true, bool pipe_stderr=true) Create a process with seven arguments. static Glib::RefPtr< process > create (std::string const &command, std::string const &a1, std::string const &a2, std::string const &a3, std::string const &a4, std::string const &a5, std::string const &a6, std::string const &a7, std::string const &a8, bool pipe_stdin=true, bool pipe_stdout=true, bool pipe_stderr=true) Create a process with eight arguments. static Glib::RefPtr< process > create (std::string const &command, std::string const &a1, std::string const &a2, std::string const &a3, std::string const &a4, std::string const &a5, std::string const &a6, std::string const &a7, std::string const &a8, std::string const &a9, bool pipe_stdin=true, bool pipe_stdout=true, bool pipe_stderr=true) Create a process with nine arguments. Detailed Description Create a process, optionally connection its standard in- and output streams to the calling program. Member Function Documentation static std::string shevek::process::run (std::string const &command, std::string const &sh) [static] Run a process and return its output. A convenience function for running a process and catching its standard output in a string. This blocks until the process has exited. static Glib::RefPtr<process> shevek::process::shell (std::string const &command, boolpipe_stdin = true, boolpipe_stdout = true, boolpipe_stderr = true, std::string const &sh = '/bin/sh') [inline, static] Run a string with the shell. Note that the process is forked from the shell, and so does not get killed when the process goes away. Author Generated automatically by Doxygen for libshevek from the source code. libshevek Fri May 11 2012 shevek::process(3)
All times are GMT -4. The time now is 08:48 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy