Selecting specific variable in log file


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Selecting specific variable in log file
# 1  
Old 07-13-2017
Last entry in log file

Hi there

I am trying to look for a specific word in the log file and I am aware this can be done by grep for example.

As there will be multiple entries for this I want to grep the last one to enter the log... how would I go about this - would I have to use tail?

Thanks in advance

Alex

Last edited by simpsa27; 07-17-2017 at 05:49 AM..
# 2  
Old 09-03-2017
Did you try:
Code:
grep pattern filename | tail -1

# 3  
Old 09-03-2017
How about
Code:
tac file | grep -m1 pattern

? It will save reading / searching through the entire file, esp. interesting for large files.
# 4  
Old 09-03-2017
tac does read the entire file.?
With sed
Code:
sed -n '/pattern/x;$x;$p' file

# 5  
Old 09-04-2017
Quote:
Originally Posted by MadeInGermany
tac does read the entire file.?
.
.
.


No, it doesn't. When grep stops reading the pipe because it found the pattern and exited, tac fills it until it's full and then is killed with SIGPIPE:
Code:
lseek(3, 311877632, SEEK_SET)           = 311877632
read(3, "rag\nTestbeitrag\nTestbeitrag\nTest"..., 8192) = 8192
write(1, "itrag\nTestbeitrag\nTestbeitrag\nTe"..., 4096) = -1 EPIPE (Broken pipe)
--- SIGPIPE {si_signo=SIGPIPE, si_code=SI_USER, si_pid=4061, si_uid=1000} ---
+++ killed by SIGPIPE +++

As you can see, 311869440 (311877632 - 8192) bytes from the file have NOT been read.
This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Selecting latest entry in the log file

Hi there I am trying to write a script where I will need to look for a specific word in the log file and I am aware this can be done by grep for example. As there will be multiple entries for this I want to grep the last one to enter the log... how would I go about this - would I have to use... (5 Replies)
Discussion started by: simpsa27
5 Replies

2. Shell Programming and Scripting

selecting and deleting specific lines with condition

I have a set of data as below: The first field, $1 represent "|". The $3 (3rd field) and $6 (6th field) in my data file represent "number-molecule" which has arrangement as below: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 ... (9 Replies)
Discussion started by: vjramana
9 Replies

3. Shell Programming and Scripting

Selecting Specific Columns and Insert the delimiter TAB

Hi, I am writing a Perl Script for the below : I have a data file that consists of the header information which is 231 Lines and the footer information as 4 lines. The total number of line including the header and footer 1.2 Million with Pipe Delimited file. For example: Header Information:... (4 Replies)
Discussion started by: filter
4 Replies

4. Shell Programming and Scripting

selecting specific fields in a file (maybe with sed?)

Hi, I have a file with following lines: chr1 10 AC=2;AF=1.00;AN=2;DP=2;Dels=0.00;HRun=0;HaplotypeScore=0.00;MQ=23.00;MQ0=0;QD=14.33;SB=-10.01 chrX 18 AB=0.52;AC=1;AF=0.50;AN=2;DP=203;DS;Dels=0.00;HRun=0;HaplotypeScore=20.01;MQ=15.63;MQ0=85;QD=12.80;SB=-1289.58 I need to extract 4... (2 Replies)
Discussion started by: menenuh
2 Replies

5. Shell Programming and Scripting

Selecting specific 'id's from lines and columns using 'SED' or 'AWK'

Hello experts, I am new to this group and to 'SED' and 'AWK'. I have data (text file) with 5 columns (C_1-5) and 100s of lines (only 10 lines are shown below as an example). I have to find or select only the id numbers (C-1) of specific lines with '90' in the same line (of C_3) AND with '20' in... (6 Replies)
Discussion started by: kamskamu
6 Replies

6. UNIX for Dummies Questions & Answers

Selecting specific line using awk

Hi, I would like to get the specific line from the file taking specific coloumn as reference. Thanks and Regards (1 Reply)
Discussion started by: kkarthik_kaja
1 Replies

7. Shell Programming and Scripting

Selecting rows with a specific criteria

Hi, I want a UNIX command that can filter out rows with certain criteria. The file is tab deliminated. Row one is just a value. Basically what I want to do is select based on the name and character at the end (o). So lets lets say i want a row that has WashU and (o) then it would print... (2 Replies)
Discussion started by: phil_heath
2 Replies

8. UNIX for Dummies Questions & Answers

command for selecting specific lines from a script

I need help on following script: I need to print the lines which are in bold letters in separate file as record string("|") emp_name; string("|") emp_id; decimal("|") emp_salary; string("|") emp_status; string("\n") emp_proj; end (1 Reply)
Discussion started by: gardasgangadhar
1 Replies

9. UNIX for Dummies Questions & Answers

Help with selecting specific lines in a large file

Hello, I need to select the 3 lines above as well as below a search string, including the search string. I have been trying various combinations using sed command without any success. Can anuone help please. Thanking (2 Replies)
Discussion started by: tansha
2 Replies

10. Shell Programming and Scripting

Urgent: selecting unique specific content of a file using shell script

Hi, I have a file whose content and format at places is as given below. print coloumn .... coloumn .... coloumn .... skip 1 line print coloumn ... skip 1 line I need to select the following : print coloumn .... coloumn .... coloumn... (2 Replies)
Discussion started by: jisha
2 Replies
Login or Register to Ask a Question