Get last lines of file after last line with word TEST


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get last lines of file after last line with word TEST
# 1  
Old 10-06-2010
Get last lines of file after last line with word TEST

i need to get least lines of file after last word TEST in file, and send that lines to mail

example of file structure:
Code:
TEST 10.10.2010
jdfjdnjfndjfndnfkdk
djfjdnfjkdjkfnjkdfk
jdfjdjfnjdjnfjkdnfjk

TEST 11.10.2010
jdjfnjdnfdkdfjdfjdnk
jdnfjdnjkfndnfjdnfjk
fjdnfjkndnfdfnjdnfjk

TEST 12.10.2010
sddhbfhjdbfhdbjbfj
dhbfhdfbdbfhjdbfjb
jndjkfndnfjkdnfkfnk
...
...

Moderator's Comments:
Mod Comment Having 11 posts you should be familiar with code tags so please use them next time. You got a PM.

Last edited by waso; 10-06-2010 at 07:31 AM..
# 2  
Old 10-06-2010
Code:
$ ruby -00 -ne 's=$_;END{print s}' file

# 3  
Old 10-06-2010
like this:

Code:
 
awk '/TEST/ { s=" "; s=$0;next } {s=s"\n" $0} END { print s}' input_file

# 4  
Old 10-06-2010
i forget, i need to send this lines on mail
# 5  
Old 10-06-2010
save the output into a temp file.

man "mail" give you more information on how to send a mail.

remove the temp file
# 6  
Old 10-06-2010
Quote:
Originally Posted by waso
i need to get least lines of file after last word TEST in file
Code:
awk '/TEST/{s=_;next}NF{s=((s)?s RS:_)$0}END{print s}' file

# 7  
Old 10-06-2010
Don't forget RS in awk.

Code:
awk 'BEGIN{RS=""} /TEST/ {t=$0}END{print t}' infile



---------- Post updated at 11:32 AM ---------- Previous update was at 11:31 AM ----------

Quote:
Originally Posted by panyam
save the output into a temp file.

man "mail" give you more information on how to send a mail.

remove the temp file
no need to save it in temp file.

Code:
awk 'BEGIN{RS=""} /TEST/ {t=$0}END{print t}' infile |mailx -s "mail subject" YOUR_MAILBOX@unix.com

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Search for word in huge logfile and need to continue to print few lines from that line til find date

Guys i need an idea for one logic..in shell scripting am struggling with a logic...So the thing is... i need to search for a word in a huge log file and i need to continue to print few more lines from that line and the consecutive line has to end when it finds the line with date..because i know... (1 Reply)
Discussion started by: Prathi
1 Replies

2. Shell Programming and Scripting

Find all lines in file such that each word on that line appears in at least n lines of the file

I have a file where every line includes four expressions with a caret in the middle (plus some other "words" or fields, always separated by spaces). I would like to extract from this file, all those lines such that each of the four expressions containing a caret appears in at least four different... (9 Replies)
Discussion started by: uncleMonty
9 Replies

3. Shell Programming and Scripting

Find word in a line and output in which line the word occurs / no. of times it occurred

I have a file: file.txt, which contains the following data in it. This is a file, my name is Karl, what is this process, karl is karl junior, file is a test file, file's name is file.txt My name is not Karl, my name is Karl Joey What is your name? Do you know your name and... (3 Replies)
Discussion started by: anuragpgtgerman
3 Replies

4. Shell Programming and Scripting

Need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line...

Hello, I need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line... An example of entries in the file would be: SRVXPAPI001 ERRO JUN24 07:28:34 1775 REASON= 0000, PROCID= #E506 #1065: TPCIPPR, INDEX= 003F ... (8 Replies)
Discussion started by: Ferocci
8 Replies

5. Shell Programming and Scripting

Read a File line by line and split into array word by word

Hi All, Hope you guys had a wonderful weekend I have a scenario where in which I have to read a file line by line and check for few words before redirecting to a file I have searched the forum but,either those answers dint work (perhaps because of my wrong under standing of how IFS... (6 Replies)
Discussion started by: Kingcobra
6 Replies

6. Shell Programming and Scripting

Grep the word from pattern line and update in subsequent lines till next pattern line reached

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

7. UNIX for Dummies Questions & Answers

How to test each line in a file

Hi guys, I have a file which contains like this: Command was launched from partition 0. ------------------------------------------------ Executing command in server server6 Event Text Mib Trap Status ... (16 Replies)
Discussion started by: rymnd_12345
16 Replies

8. Shell Programming and Scripting

get the fifth line of a text file into a shell script and trim the line to extract a WORD

FOLKS , i have a text file that is generated automatically of an another korn shell script, i want to bring in the fifth line of the text file in to my korn shell script and look for a particular word in the line . Can you all share some thoughts on this one. thanks... Venu (3 Replies)
Discussion started by: venu
3 Replies

9. Shell Programming and Scripting

replace only 1st word of a line if it comes in the subsequent lines at same postion.

I have a file like this.. Maharastra Mumbai worli Maharastra Mumbai navy maharatra Pune Maharastra Nagpur Karnataka Bangalore Karnataka Mysore Karnataka Mangalore Punjab Amritsar punjab Jalandar my expected outcome should be like this Maharastra Mumbai worli ---------- ... (9 Replies)
Discussion started by: geeko
9 Replies

10. Shell Programming and Scripting

Can a shell script pull the first word (or nth word) off each line of a text file?

Greetings. I am struggling with a shell script to make my life simpler, with a number of practical ways in which it could be used. I want to take a standard text file, and pull the 'n'th word from each line such as the first word from a text file. I'm struggling to see how each line can be... (5 Replies)
Discussion started by: tricky
5 Replies
Login or Register to Ask a Question