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 :: automate tmux 
Shell :: windows auto ip address change script 
Shell :: how to uninstall i7z on ubuntu 
Shell :: silent installation with powershell 
Shell :: snipit.io firefox extension 
Shell :: install bind9 ubuntu 16.04 
Shell :: cambiare luminosità schermo ubuntu 
Shell :: sDepends: libgcc-s1 (= 3.0) but it is not installable 
Shell :: set windows transaparancy linux 
Shell :: pip install fork branch 
Shell :: awk get last argument 
Shell :: install virtualenv ubuntu 18.04 stackoverflow 
Shell :: HFSS parametic sweep in batch 
Shell :: <bits/types/__fpos_t.h no such file or directory 
Shell :: yum snap install --classic certbot 
Shell :: ubuntu tar all .log and .txt 
Shell :: install godaddy ssl certificate on aws ec2 instance 
Shell :: zmq.hpp not found 
Shell :: interface grafica biblioteca WIN32 em Linguagem c 
Shell :: fsl remove_ext 
Shell :: how to filter output to readable characters Linux 
Shell :: Como excluir uma tag remota 
Shell :: Powershell WebAdmin 
Shell :: kill u... 
Shell :: how to print the number of columns in your terminal using tput in linux 
Shell :: pattern matching alias linux 
Shell :: use -i to suggest an answer 
Shell :: Private DNS EC2 BASH 
Shell :: powershell script to copy mutliple files into a single file 
Shell :: a2ensite example. 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =