Search for last instance of word in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search for last instance of word in a file
# 1  
Old 07-13-2010
Search for last instance of word in a file

Hi

I'm trying to search for the last instance of the word 'cache' in a HTML file that I have downloaded from YouTube.
I'm using the following syntax, but an error is thrown when I try it.
Code:
grep -f "cache"

Also I wish to append the above grep command to the below so that the search for cache is completed as part of the below script.

Code:
vidid=$(sed -n "/fmt_url_map/{s/[\'\"\|]/\n/g;p}"  $file > youtube3.html)

Thanks
Colm

Last edited by radoulov; 07-13-2010 at 04:17 PM.. Reason: Please use code tags!
# 2  
Old 07-13-2010
Tools

Code:
grep " cache" <infile | tail -1

will show last line that matches criteria
# 3  
Old 07-13-2010
Does the '<infile' relate to the file I wish to pipe it into ?
# 4  
Old 07-13-2010
Code:
while read -r LINE
do
  case "$LINE" in
      "cache" ) var=$LINE;;
  esac
done < "myfile"
echo $var

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search for a word in file and output to another

Hello Experts! I am trying to perform a common task, searching data from within a file and placing what is found into another.However, I have not been able to figure the “How to” with this situation. I need to search through all lines within this text and pull the first positional attributes... (5 Replies)
Discussion started by: leepet
5 Replies

2. Shell Programming and Scripting

Search for a specific word and print only the word from the input file

Hi, I have a sample file as shown below, I am looking for sed or any command which prints the complete word only from the input file. Ex: $ cat "sample.log" I am searching for a word which is present in this file We can do a pattern search using grep but I need to cut only the word which... (1 Reply)
Discussion started by: mohan_kumarcs
1 Replies

3. Shell Programming and Scripting

How to search a word in a file?

How to search a particular word in a file. in my file contains lacks of rows. (2 Replies)
Discussion started by: pmreddy
2 Replies

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

5. Shell Programming and Scripting

search a word and copy the file

Hi need help with a script or command My requirement is - I need to do a "ls -ltr tcserver*.syslog" files in /tmp, direct the output to a file ls -ltr tcserv*.syslog | grep "Jan 31" | awk '{printf "\n" $9}' > jandat.logs -Then open each file in above list and search for string/word,... (4 Replies)
Discussion started by: karghum
4 Replies

6. Shell Programming and Scripting

Search text file, then grep next instance of string

I need to be able to search for a beginning line header, then use grep or something else to get the very next instance of a particular string, which will ALWAYS be in "Line5". What I have is some data that appears like this: Line1 Line2 Line3 Line4 Line5 Line6 Line7 Line1 Line2 ...... (4 Replies)
Discussion started by: Akilleez
4 Replies

7. Shell Programming and Scripting

How to search for a word in a particular column of a file

How to search for a word like "computer" in a column (eg: 4th field) of a '***' delimited file and add a column at the end of the record which denotes 'Y' if present and 'N' if not. After this, we need to again check for words like 'Dell' but not 'DellXPS' in 5th field and again add another column... (5 Replies)
Discussion started by: Jassz
5 Replies

8. UNIX for Dummies Questions & Answers

Search a specific word from any one of the file.

how do i Search a specific word from any one of the file.? (1 Reply)
Discussion started by: ritusubash
1 Replies

9. Shell Programming and Scripting

Search the last instance of a string in a file

I have a big database log file which keepsgrowing daily. OS is HP UX. Here is a small part of it: Tue Jan 27 04:03:22 2009 : add session begin for mfgeb on /dev/pts/th. : Converting relative path to absolute path. : add session end. Tue Jan 27 04:03:29... (6 Replies)
Discussion started by: dinesh1178
6 Replies

10. Shell Programming and Scripting

search a word from file

Hello, I have a file which contains some SQL statements. I need to take out the table name from the file. Table name will always end with "_t". can anyone help me in getting that? for e.g. --- SQL_STMT do_sql_insert: cmd="insert into account_t ( poid_DB, poid_ID0, poid_TYPE, poid_REV,... (9 Replies)
Discussion started by: vishy
9 Replies
Login or Register to Ask a Question