Grep the word at the end of the file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Grep the word at the end of the file
# 1  
Old 05-20-2009
Grep the word at the end of the file

I need to grep the word "hello" in each and every file. This word will be placed either at the end of the file or before the end of the file.

Ex:

file1: file2:

afdsaf dsfalk
fdsa weruoi
sdaf erwqiuo
fsdaf hello
fsda ewrqpoi
hello rewk
dfsdfsa fdskja;f
dfsaf

It will be like this..In short the word hello have to be grepped from the last 10 lines of each file....

Pls help on this...
# 2  
Old 05-20-2009
a small addition on this...I need to find the list of the files which does not have the word "hello" at the last 10 lines of each files....
# 3  
Old 05-20-2009
if you are sure there is only 1 hello in your files, just do a grep.
however, if there are more than one hello and you only want to get the last hello,
Code:
awk '/hello/{s=$0}END{print s}' file

# 4  
Old 05-20-2009
Quote:
Originally Posted by sivakumar.rj
a small addition on this...I need to find the list of the files which does not have the word "hello" at the last 10 lines of each files....
if you want to search hello word in last 10 lines of each file
take each file one by one via for loop
then
tail -10 filename|grep -q "hello"
then check for the status using $?
if its 1 that file doesnot have hello in last 10 lines otherwise it has.
# 5  
Old 05-20-2009
Will this awk command searches for the whole directory..
# 6  
Old 05-20-2009
use a for loop (or find command for recursive) to go through files.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep a log file starting from a specific time to the end of file

I have a log file which have a date and time at the start of every line. I need to search the log file starting from a specific time to the end of file. For example: Starting point: July 29 2018 21:00:00 End point : end of file My concern is what if the pattern of `July 29 2018 21:00:00`... (3 Replies)
Discussion started by: erin00
3 Replies

2. Shell Programming and Scripting

Grep from match to the end of file

Hi i have this script : #!/bin/bash DATE=$(date '+%Y-%m-%d %H:%M' -d "1 hour ago") PASS=$(grep -A99999999999 '$DATE' /var/log/asterisk/full| grep -i 'Wrong password') it a script that ment to go over log file a hour back from now until the end of file. right now im using... (5 Replies)
Discussion started by: batchenr
5 Replies

3. Shell Programming and Scripting

Add words in beginning , end after removing a word in a file

My file has the entries like below... /dev/sds /dev/sdak /dev/sdbc /dev/sdbu I want to make the file like below echo 1 > /sys/block/sds/device/rescan echo 1 > /sys/block/sdak/device/rescan echo 1 > /sys/block/sdbc/device/rescan echo 1 > /sys/block/sdbu/device/rescan (2 Replies)
Discussion started by: saravanapandi
2 Replies

4. Shell Programming and Scripting

How to append word count at end of file?

Hi guys, I have to append the word count of a file at the end of the file name like this - > "filename_2345" where 2345 is the word count of "filename". How do i achieve this using one command ? I am not allowed to store the word count in a variable and then concatenate. Request your... (1 Reply)
Discussion started by: peter2312
1 Replies

5. Shell Programming and Scripting

How can I just grep one instance of a word in the file

I want to grep some information out of the dmidecode but when I type dmidecode | grep Memory I get several instances of the word. Is there a way I can just choose which instance I want to display? (8 Replies)
Discussion started by: jcnewton13
8 Replies

6. Shell Programming and Scripting

how to move a word to the end of file

Hey guys, I want move a specific word from the middle of the text and move it the end of the file, which means I want the word to be deleted from it's line and moved to the end of file. I know how to use sed for adding a word the end of file, but I don't know how to move words. tnx (2 Replies)
Discussion started by: Johanni
2 Replies

7. Shell Programming and Scripting

Append the text file with comma at the end of every word

Hi folks, Using shell, I am trying the append comma to every line of text. the requirement is like, I have to open the txt file in unix and read line by line and should add comma at the end of every word to make it single line txt file ------- abc@gmail.com bcd@gmail.com... (7 Replies)
Discussion started by: giridhar276
7 Replies

8. UNIX for Dummies Questions & Answers

deleting word from this point to end of file in VI

Hi All i need to delete a recurring word from point "n" till end of the file. there are other words in this file so i cannot use `dG`, can anyone help me out? Kind regards Brian (4 Replies)
Discussion started by: brian112
4 Replies

9. Shell Programming and Scripting

grep second word in a file

How do I match second word and then print that line to output For eg: My file has following text and I want to check if second word is n then I want to print entire line . xytxti8naclip y xytxt32bpsimple y xytxt32bpna n xytxti16nae y xysmps32bpp031_bst n... (7 Replies)
Discussion started by: pitagi
7 Replies

10. Shell Programming and Scripting

Add a word at the end of each line in a file

Hi I want to read a flat file and add a word/value at the end of each line in the file and store the output in a temporary file. How can i do this? Plz help me with this. Regards, Saurabh (6 Replies)
Discussion started by: bhalotias
6 Replies
Login or Register to Ask a Question