You could try
grep pattern file | tail -1
or
tac file | grep pattern | head -1
or
tac file | grep -m1 pattern
Related Posts:
- How to pretty print XML from the command line?
- What are file descriptors, explained in simple terms?
- How do I grep recursively?
- How do I grep recursively?
- grep –ignore-case –only
- How to kill a process running on particular port in Linux?
- Display exact matches only with grep
- How do I grep recursively?
- How to split a delimited string into an array in awk?
- How do I use grep to search the current directory for all files having the a string “hello” yet display only .h and .cc files?
- Display exact matches only with grep
- How can I exclude directories from grep -R?
- How can I exclude directories from grep -R?
- What does ^M character mean in Vim?
- What does it mean to write to stdout in C?
- What do ‘real’, ‘user’ and ‘sys’ mean in the output of time(1)?
- mkdir’s “-p” option
- wait(null) and wait(&status) C language and Status
- Shell script “for” loop syntax
- Diff command along with Grep gives “Binary file (standard input) matches”
- How to get the current directory in a C program?
- When could or should I use chmod g+s on a file or directory?
- How to Sum a column in AWK?
- Equivalent of *Nix ‘which’ command in PowerShell?
- What is the difference between SIGSTOP and SIGTSTP?
- How to colorize diff on the command line
- How to colorize diff on the command line
- How to read a file into a variable in shell?
- gpg decryption fails with no secret key error
- What is the difference between tar and zip?
- Display current path in terminal only
- What do the dup() and dup2() systems really do?
- Using grep and ls -a commands
- What generates the “text file busy” message in Unix?
- Reasoning behind C sockets sockaddr and sockaddr_storage
- How can I send an email through the UNIX mailx command?
- grep for special characters in Unix
- Rename multiple files based on pattern in Unix
- What is the difference between a symbolic link and a hard link?
- SCP Permission denied (publickey). on EC2 only when using -r flag on directories
- binary operator expected error when checking if a file with full pathname exists
- What is special about /dev/tty?
- How do I do ‘mount –bind’ in /etc/fstab?
- How to read backward from the end of file in less or more?
- How do I pause my shell script for a second before continuing?
- What is newline character — ‘\n’
- How can I exclude one word with grep?
- Why does ENOENT mean “No such file or directory”?
- sudo: npm: command not found
- In the shell, what does ” 2>&1 ” mean?
- What are good grep tools for Windows? [closed]
- What is the meaning of *nix?
- How do I find all files containing specific text on Linux?
- PowerShell equivalent to grep -f
- In the shell, what does ” 2>&1 ” mean?
- How to grep for case insensitive string in a file?
- What are .a and .so files?
- How to perform grep operation on all files in a directory?
- How can I check if a directory exists in a Bash shell script?
- OS X: equivalent of Linux’s wget
- Connect: Socket operation on non-socket
- Connect: Socket operation on non-socket
- What is the difference between read and pread in unix?
- OS X: equivalent of Linux’s wget
- SSH using python script
- Grep and Python
- Argument list too long error for rm, cp, mv commands
- Difference between using “chmod a+x” and “chmod 755”
- What is a bus error? Is it different from a segmentation fault?
- What does WEXITSTATUS(status) return?
- Using the star sign in grep
- Who can access a file with octal permissions “000” on Linux/UNIX?
- What does the line “#!/bin/sh” mean in a UNIX shell script?
- How to cat <
> a file containing code? - Extract file basename without path and extension in bash
- Given two directory trees, how can I find out which files differ by content?
- Which characters need to be escaped when using Bash?
- OSError – Errno 13 Permission denied
- What is cp: cannot stat error in Unix, I get this error when trying to copy thing from one folder to another
- Delete all local git branches
- cp: missing destination file operand after
- What is a bus error? Is it different from a segmentation fault?
- What can cause a “Resource temporarily unavailable” on sock send() command
- Grep ‘binary file matches’. How to get normal grep output?
- Negative matching using grep (match lines that do not contain foo)
- How to download a file from server using SSH?
- What is the ASCII Code of ½?
- Get Unix timestamp with C++
- Validating IPv4 addresses with regexp
- What is cp: cannot stat error in Unix, I get this error when trying to copy thing from one folder to another
- What is the difference between “#!/usr/bin/env bash” and “#!/usr/bin/bash”?
- How can I “grep” for a filename instead of the contents of a file?
- Why should we check WIFEXITED after wait in order to kill child processes in Linux system call?
- What does `set -x` do?
- Command to change the default home directory of a user
- Is there any simple way to benchmark Python script?
- How to get the process ID to kill a nohup process?
- Sorting data based on second column of a file
- How to grep and replace
- Is there a Pattern Matching Utility like GREP in Windows?