Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

sed remove line after match

Use d option at the end of sed command string for deleting line of matches.
sed -i "" "s/matching_pattern/,+1 d" file.txt #+1 defines number of lines
# to delete after matching line
Comment

sed delete line before match

Use d option at the end of sed command string for deleting line of matches.
tac | sed -i "" "s/matching_pattern/I+1 d" file.txt | tac #
Comment

sed delete line match

sed '/pattern to match/d' ./infile
Comment

delete strings after match to eol using sed command

$ cat file | awk -F '.com' '{print $1".com"}'
google.com
unix.stackexchange.com
isuckatunix.com
Comment

delete strings after match to eol using sed command

# To explicitly delete everything that comes after ".com", just tweak your existing sed solution to replace ".com(anything)" with ".com":
sed 's/.com.*/.com/' file.txt
Comment

delete strings after match to eol using sed command

# You can use awk's field separator (-F) following way:
$ cat file
google.com/funny
unix.stackexchange.com/questions
isuckatunix.com/ireallydo
Comment

PREVIOUS NEXT
Code Example
Shell :: how to update git in vscode 
Shell :: How do I run multiple commands on one line in PowerShell? 
Shell :: kubernetes shell into pod 
Shell :: homebrew on mac 
Shell :: install brew on mac terminal 
Shell :: brew mac 
Shell :: download code from github 
Shell :: install dlib gpu check 
Shell :: get all branches git 
Shell :: git origin command 
Shell :: overall configuration gzip compression with nginx 
Shell :: giving permission to folder in ubuntu 
Shell :: pip 21.0.1 install windows 
Shell :: git empty commit 
Shell :: replace using sed 
Shell :: ubuntu console png to pdf 
Shell :: running shell commands nodejs 
Shell :: install wordcloud anaconda jupyter notbook 
Shell :: brew install docker 
Shell :: adb screen record 
Shell :: git get OR show commit date 
Shell :: docker wordpress 
Shell :: git clone tag 
Shell :: how to check is heroku git remote is added 
Shell :: install spotify-web-api-js 
Shell :: phpcs standard xml 
Shell :: how to revert a merge locally 
Shell :: git lang 
Shell :: delete a file from repo history 
Shell :: kubectl exec run command inside pod 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =