01-31-2008
grep required pattern and next 2 or 3 lines
dear ones
pl.kindly help me 1) how to print(grep) required pattern and following 2 or 3 lines. 2) grep required pattern(to print)+above 2 lines+below 2 or 3 lines.from a report file.
ex:
we have some report file
kf askfjsk fksaj fk skf sjfksjd kff sjfkjs kf jskdjfklsd jfklsdf sdkfjsd fsd
jkfsdja fkjsdklf jsdklfj klsdj fklsd jkfjsdkfj ksd jfksdjf 456015
jf sakjlf ksld flksdjklfj sakl jfklsdajklfj sdalfjsdj fksldjfls djfkl
i want to print 456015 and next 1 or 2 lines in some cases. and 456015 + above one line +below 1 or 2 lines.
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
OK. I have a file I'd like to be able to grep, but on top of returning the line where the pattern matches, I'd like to be able to get the previous 8 lines and the following 8 lines. Is there a way to do this? (2 Replies)
Discussion started by: mrwatkin
2 Replies
2. Shell Programming and Scripting
Hi experts
I want the proper argument to the grep command so that I need to skip the first few lines(say first 10 lines) and print all the remaining instances of the grep output.
I tried to use grep -m 10 "search text" file*. But this gives the first 10 instances(lines) of the search string.... (7 Replies)
Discussion started by: ks_reddy
7 Replies
3. Shell Programming and Scripting
Hi All,
I need your help in finding pattern from files present in different directories.
I need to search for a pattern "xyz" from "*.txt" files which are present in different levels of directories as shown.
example
-------
dir1/subdir1/file.txt
dir2/subdir2/subsubdir2/file.txt... (5 Replies)
Discussion started by: imas
5 Replies
4. Shell Programming and Scripting
Hi,
I have two files say xxx.txt and yyy.txt. xxx.txt is with list of patterns within double quotes. Eg.
"this is the line1"
"this is the line2"
The yyy.txt with lot of lines. eg:
"This is a test message which contains rubbish information just to fill the page which is of no use. this is... (3 Replies)
Discussion started by: abinash
3 Replies
5. Shell Programming and Scripting
Hi,
I have got the below requirement. please suggest.
I have a file like,
Processing Item is:
/data/ing/cfg2/abc.txt
/data/ing/cfg3/bgc.txt
Processing Item is:
/data/cmd/for2/ght.txt
/data/kernal/config.klgt.txt
I want to process the above file to get the output file like,
... (5 Replies)
Discussion started by: rbalaj16
5 Replies
6. Shell Programming and Scripting
Hi Experts,
Need help with the following:
Desired output:
Only want to get the output marked in green.
The file:
--- Physical volumes ---
PV Name /dev/disk/disk4704
PV Status available
Total PE 6399
Free PE ... (3 Replies)
Discussion started by: rveri
3 Replies
7. Shell Programming and Scripting
Hi All,
I am trying to fetch lines before a pattern, I got to know about -B flag in grep but we have to pass the number to get those lines before some pattern say (X), now what if I want to get line/s with some other pattern say (Y) before X pattern? How to get about it? please help.
Input:... (5 Replies)
Discussion started by: dips_ag
5 Replies
8. UNIX for Dummies Questions & Answers
Hi all!
Thanks for taking the time to view this!
I want to grep out all lines of a file that starts with pattern 1 but also does not match with the second pattern.
Example:
Drink a soda
Eat a banana
Eat multiple bananas
Drink an apple juice
Eat an apple
Eat multiple apples
I... (8 Replies)
Discussion started by: demmel
8 Replies
9. Shell Programming and Scripting
Linux version : Oracle Linux 6.5
Shell : bash
In the the below text file (someString.text), I want to grep all lines with .sh in it. ie. Only the lines mysript.sh and anotherscript.sh should be returned.
My below attempts failed.
I gather that in regular expression world, dot (.) is the... (3 Replies)
Discussion started by: John K
3 Replies
10. UNIX for Beginners Questions & Answers
Hi All,
i want to write a shell script read below file line by line and want to exclude the lines which contains empty value for MOUNTPOINT field.
i am using centos 7 Operating system.
want to read below file.
# cat /tmp/d5
NAME="/dev/sda" TYPE="disk" SIZE="60G" OWNER="root"... (4 Replies)
Discussion started by: balu1234
4 Replies
PRINT(3) 1 PRINT(3)
print - Output a string
SYNOPSIS
int print (string $arg)
DESCRIPTION
Outputs $arg.
print is not actually a real function (it is a language construct) so you are not required to use parentheses with its argument list.
PARAMETERS
o $arg
- The input data.
RETURN VALUES
Returns 1, always.
EXAMPLES
Example #1
print examples
<?php
print("Hello World");
print "print() also works without parentheses.";
print "This spans
multiple lines. The newlines will be
output as well";
print "This spans
multiple lines. The newlines will be
output as well.";
print "escaping characters is done "Like this".";
// You can use variables inside a print statement
$foo = "foobar";
$bar = "barbaz";
print "foo is $foo"; // foo is foobar
// You can also use arrays
$bar = array("value" => "foo");
print "this is {$bar['value']} !"; // this is foo !
// Using single quotes will print the variable name, not the value
print 'foo is $foo'; // foo is $foo
// If you are not using any other characters, you can just print variables
print $foo; // foobar
print <<<END
This uses the "here document" syntax to output
multiple lines with $variable interpolation. Note
that the here document terminator must appear on a
line with just a semicolon no extra whitespace!
END;
?>
NOTES
Note
Because this is a language construct and not a function, it cannot be called using variable functions.
SEE ALSO
echo(3), printf(3), flush(3), Heredoc syntax.
PHP Documentation Group PRINT(3)