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 :: scp linux to mac 
Shell :: install zipalign kali linux 
Shell :: git assume undo unchanged 
Shell :: bash exit code 
Shell :: powershell global variable 
Shell :: linux ip route add 
Shell :: env file in firebase 
Shell :: brew show package info 
Shell :: delete a git branch 
Shell :: reset git file 
Shell :: how to create a branch in git 
Shell :: github.com api 
Shell :: uname linux 
Shell :: failed to start high performance web server and reverse proxy 
Shell :: bash get files older than 
Shell :: what is a shebang line 
Shell :: how to check raspbian os version 
Shell :: find the process ID of a running process bash 
Shell :: powershell script run 
Shell :: how to install pytesseract in rpi 
Shell :: ssh option to send null packets 
Shell :: Building without Cython. Error: Please make sure the libxml2 and libxslt development packages are installed. 
Shell :: bash: udevadm: command not found 
Shell :: xcode errSecInternalComponent 
Shell :: shortan promt ubunto 
Shell :: brew install older version opencv 
Shell :: deploying to heroku from git 
Shell :: install firefox redhat 7 
Shell :: apache2 mod_jk proxy to tomcat connector 
Shell :: color picker snap 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =