Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

bash grep only return first match

# Basic syntax:
grep -m 1 "pattern" input_file.txt
# Where -m is the maximum number of matching lines to return, i.e. stop
#	reading the file after m matches
# Note, this is more efficient than piping to head because there you
#	always read the whole file even if you're only looking for m matches
Comment

grep first match

Just combine grep with head command for filtering  only the first match as:
grep "match" | head -n 1   #Change 1 to not only match first but further matches
Comment

PREVIOUS NEXT
Code Example
Shell :: apt use ipv4 
Shell :: responsive grid system angular 
Shell :: no build file in linux headers 
Shell :: open wsl as root 
Shell :: git log by date 
Shell :: bash copy directory 
Shell :: yusuke persona 5 
Shell :: adb devices offline 
Shell :: install ip addr on ubuntu 
Shell :: git new repo instructions 
Shell :: how to run an appimage in linux 
Shell :: how to stop a web server linux 
Shell :: kali linux upgrade to new version 
Shell :: git ignore remove 
Shell :: selinux disable ubuntu 
Shell :: list usb devices linux 
Shell :: install chromedriver linux command line 
Shell :: bash parameters after first 
Shell :: php runing using aphp.ini 
Shell :: how to install ansible in debian 
Shell :: lollypop music player install ubuntu 
Shell :: linux install fzf 
Shell :: change gunicor port and to https 
Shell :: moodle purge cache from command line 
Shell :: install virtual environment ubuntu 
Shell :: borrar una rama git 
Shell :: qts linux show process port 
Shell :: linux command to get number of lines in a file 
Shell :: ubuntu command history 
Shell :: Consider using absolute ordering 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =