Sponsored Content
Top Forums Shell Programming and Scripting Grep from match to the end of file Post 302987129 by batchenr on Tuesday 6th of December 2016 01:31:44 AM
Old 12-06-2016
thanks for your answer!

rbatte1:

Code:
last_line=$(grep -n "Your search text here" input_file | tail -1 | cut -f 1 -d ":")

((last_line=$last_line-1))               # To include current line in the next step

sed -n "$last_line,\$"p input_file

what it did is to give me the line in the log which it have found my word:
Code:
last_line=$(grep -n "Wrong password" /var/log/asterisk/full-20161205 | tail -1 | cut -f 1 -d ":")

gave me : 37171

then i did
Code:
((last_line=$last_line-1))

whichgave me this :
37171-1 as a varible

and when i ran
Code:
sed -n "$last_line,\$"p  /var/log/asterisk/full-20161205

i got :
Code:
sed: -e expression #1, char 6: unknown command: `-'

------------------------------------------------------------------------------

RudiC:

thanks ! it did the trick :

Code:
awk -v DT="$DATE" '($1 " " $2) >= DT'   /var/log/asterisk/full-20161205 | grep "password"

finds from hour back to the end of file! Smilie
Moderator's Comments:
Mod Comment Please use CODE tags (not ICODE tags) when displaying full line and multi-line sample input, sample output, and code segments.

Last edited by Don Cragun; 12-06-2016 at 02:54 AM.. Reason: Change most ICODE tags to CODE tags.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

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 ... (5 Replies)
Discussion started by: sivakumar.rj
5 Replies

2. UNIX for Dummies Questions & Answers

Lynx Grep Pattern Match 2 conditions Print from Start to End

I am working on a scraping project and I am stuck at this tiny grep pattern match. Sample text : FPA List. FPA List. FPA List. FPA List. FPA List. FPA List. FPA List. FPA List. ABC Personal Planning Catherine K. Wat Cath Wat Catherine K. Wat Catherine K. Wat IFRAME:... (8 Replies)
Discussion started by: kkiran
8 Replies

3. Shell Programming and Scripting

Grep from a starting line till the end of the file

Hi Folks, I got to know from this forums on how to grep from a particular line say line 6 awk 'NR==6 {print;exit}' But how do i grep from line 6 till the end of the file or command output. Thanks, (3 Replies)
Discussion started by: Mr. Zer0
3 Replies

4. Shell Programming and Scripting

sed print from last occurrence match until the end of file

Hi, i have file f1.txt with data like: CHECK a b CHECK c d CHECK e f JOB_START .... I want to match the last occurrence of 'CHECK' until the end of the file. I can use awk: awk '/^CHECK/ { buf = "" } { buf = buf "\n" $0 } END { print buf }' f1.txt | tail +2Is there a cleaner way of... (2 Replies)
Discussion started by: ysrini
2 Replies

5. Shell Programming and Scripting

AWK-grep from line number to the end of file

Does anyone know how to use awk to act like grep from a particular line number to the end of file? I am using Solaris 10 and I don't have any GNU products installed. Say I want to print all occurrences of red starting at line 3 to the end of file. EXAMPLE FILE: red green red red... (1 Reply)
Discussion started by: thibodc
1 Replies

6. Shell Programming and Scripting

Pattern match till the end of the file.

I have a file which is like this ……………………………………….. ………………………………… ………………………………… …………………………………… ……………………………………. ……………………………… <<<from_here>>> ……………………………… ………………………………. I want a script which would fetch the data starting from <<<from_here>>> in the file till the end... (2 Replies)
Discussion started by: halfafringe
2 Replies

7. Shell Programming and Scripting

Grep start and end line of each segments in a file

Cat file1 -------- ---------- SCHEMA.TABLE1 insert------- update----- ------------- ---------- SCHEMA.TABLE2 insert------- update----- ----------- ------------ SCHEMA.TABLE3 insert------- update----- ------------ grep -n SCHEMA > header_file2.txt (2 Replies)
Discussion started by: Veera_V
2 Replies

8. Shell Programming and Scripting

Search from 1st match and end 2nd match

I've been looking through the forums for awhile now and looking at the man page for grep and egrep and not seeming to find this scenario so it might not be possible but figured I'd throw it out to get some ideas. I'm looking for a way to search a file for 1st match (example below net self) and... (3 Replies)
Discussion started by: djzah
3 Replies

9. Shell Programming and Scripting

Grep for an exact match in a file

I am currently having some issues while trying to grep for a exact string inside a file. I have tried doing this from command line and things work fine i.e. when no match is found, return code=1 but when its done as part of my script it returns 0 for the same command - I dont know if there is an... (6 Replies)
Discussion started by: Ads89
6 Replies

10. 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
All times are GMT -4. The time now is 05:12 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy