Sponsored Content
Top Forums Shell Programming and Scripting Printing all lines before a specific string and a custom message 2 lines after Post 302515804 by SEinT on Thursday 21st of April 2011 02:27:00 AM
Old 04-21-2011
Printing all lines before a specific string and a custom message 2 lines after

Hello all,

I need to print all the lines before a specific string and print a custom message 2 lines after that.

So far I have managed to print everything up the string, inclusively, but I can't figure out how to print the 2 lines after that and the custom message.

My code thus far is:
Code:
'{a[NR]=$0} ($3 ~ "Bob") {for(x=1; x<=$1; x++) {print a[x]}}'

My data is similar to the following:
Code:
Don|Joe|Lue
Mary|Elane|Bob
David|Mark|Steven
John|Jim|William
Sal|Jose|Michael

I would like to get the following result once "Bob" is matched:
Code:
Don|Joe|Lue
Mary|Elane|Bob
David|Mark|Steven
John|Jim|William
STOPPING HERE          #This being the custom message

Thanks in advance
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Printing lines with specific awk NF

I have this files: ./frm/lf_mt1_cd.Ic_cell_template.attr ./die/addgen_tb_pumd.Ic_cell_template.attr ./min_m1_n.Ic_cell_template.attr When I use: awk -F\/ '{print NF}' Would result to: 3 3 2 I would like to list the files with 3 fields on it. Any Suggestions? (1 Reply)
Discussion started by: jehrome_rando
1 Replies

2. Shell Programming and Scripting

Printing the lines which proceeds the particular string

Hi, We are facing some issues while finding the particular string. Our file is: cat 1.txt Node Name(s) Preparation fragment Partition: Transformation instance: Transformation: Applied rows: Affected rows: Rejected rows: Throughput(Rows/Sec): Throughput(Bytes/Sec): Last... (3 Replies)
Discussion started by: Amey Joshi
3 Replies

3. Shell Programming and Scripting

printing lines to a file from a particular string

Hi, A very Good Evening to All, I am writing a script for my application. I have a file with 1000 lines. Among that 1000 lines i am searching for a particular string. And from that string i need to pull all the data in to a seperate file. For example the contents of my file is as below. ... (4 Replies)
Discussion started by: intiraju
4 Replies

4. Shell Programming and Scripting

Printing 10 lines above and below the search string: help needed

Hi, The below code will search a particular string(say false in this case) and return me 10 lines above and below the search string in a file. " awk 'c-->0;$0~s{if(b)for(c=b+1;c>1;c--)print r;print("***********************************");print;c=a;}b{r=$ 0}' b=10 a=10 s="false" " ... (5 Replies)
Discussion started by: vimalm22
5 Replies

5. Shell Programming and Scripting

substitute a string on a specific position for specific lines

I woud like to substitue a string on a specific position for specific lines I've got a file and I would like to change a specific string from "TOCHANGE" to "ABCABCAB" For every line (except 1,2, 3 and the last one) , I need to check between the 9th and the 16th digits. For the 3rd line, I... (7 Replies)
Discussion started by: BSF
7 Replies

6. Shell Programming and Scripting

Printing several lines of a file after a specific expression

Hello, I want to print a number of lines of a file after a specific expression of a line. I have this sed command but it prints only 1 line after the expression. How could I adapt it to print for instance 10 lines after or 15 lines after ? sed -n '/regexp/{n;p;}' Thx & Regs, Rany. (5 Replies)
Discussion started by: rany1
5 Replies

7. Shell Programming and Scripting

Printing the lines of the string with highest value

Please help . The script need to first grep for all lines with "C:" as it contains a value Here the value is 0 1,00: This , is a good script c:0 and then give output of the lines with top 3 highest value for c: 1,00: This , is a nice script c:9999 1,00: This , is a... (3 Replies)
Discussion started by: necro98
3 Replies

8. Shell Programming and Scripting

Printing next two lines from a file after grepping a specific pattern

Hi I have a file like # vi require.txt 1,BANK,Read blocks that cycle. yellow Read blocks. 2,ACCOUNT,Finished Red Finished . 3,LOAN, pipe white pipe 4,PROFIT,Resolve. black Resolve Am using like cat require.txt | grep -w ACCOUNTThe output I get is (8 Replies)
Discussion started by: Priya Amaresh
8 Replies

9. UNIX for Dummies Questions & Answers

Printing lines with specific strings at specific columns

Hi I have a file which is tab-delimited. Now, I'd like to print the lines which have "chr6" string in both first and second columns. Could anybody help? (3 Replies)
Discussion started by: a_bahreini
3 Replies

10. Shell Programming and Scripting

Printing multiple lines on the same line between specific text

This is an extract from a large file. The lines that start with fc are ports on a fabric switch. In between each fc port there is information about the port. fc2/12 is up Port description is SEIEDISCOVER-3 Speed is 4 Gbps fc2/13 is down (Administratively down) fc2/14 is up Port... (1 Reply)
Discussion started by: kieranfoley
1 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)
All times are GMT -4. The time now is 05:36 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy