Skip to main content

Linux command: sed

sed - Stream EDitor for filtering and transforming text

Delete the 2nd line in ~/.ssh/known_hosts

sed -i '2d' .ssh/known_hosts

Delete all lines start with #

sed -i '/^#/d' /etc/squid/squid.conf

Delete all blank lines

sed -i '/^$/d' /etc/squid/squid.conf

Replace trailing spaces with colon

# cat sed1.txt
user         password
haxor                    lsatsdf
nomandad xiftox123
nobita             shizuka<3
xadminx      needme?$
peterpan               TinkerBell69
satan           GOAT
# cat sed1.txt | sed -E 's/\s+/:/'
user:password
haxor:lsatsdf
nomandad:xiftox123
nobita:shizuka<3
xadminx:needme?$
peterpan:TinkerBell69
satan:GOAT

Remove/Delete all digits

# cat sed2.txt | sed -E 's/[[:digit:]]//'
C3453453O24N3452G345RA3T45345U3245L435A344T5I45ON3245S34
Y334523455O375678748U8
678778M68797998058746A7524534D6234534532545E45234534522
45345534I24354352435565T24356675463524435
3423466567T454564775367H3632452345R2345OU3G6H464456356453
T5H3452354235I45656565647S567567457
S536235342654763M45633465457346246536A75673475683647L38765877943675626765L686978437566
4256457642635345L23654325341545637235I34263462435346563456T34526457832435424TL4546375683654657463E
C5234645365H4653634453647A42353657346334643426858678845735625L342142352455675L213412416757E213423152345658N2314314163776G211235E2
# cat sed2.txt | sed -E 's/[[:digit:]]//g' | tr '\n' ' '
CONGRATULATIONS YOU MADE IT THROUGH THIS SMALL LITTLE CHALLENGE
#

Practice

>>> THM | Linux Modules - Task 7

References

Sed - An Introduction and Tutorial by Bruce Barnett

Popular posts from this blog

Linux command: lastlog

lastlog command reports the most recent login of all users or of a given user. NAME lastlog - reports the most recent login of all users or of a given user SYNOPSIS lastlog [options] DESCRIPTION lastlog formats and prints the contents of the last login log /var/log/lastlog file. The login-name, port, and last login time will be printed. The default (no flags) causes lastlog entries to be printed, sorted by their order in /etc/passwd. OPTIONS The options which apply to the lastlog command are: -b, --before DAYS Print only lastlog records older than DAYS. -h, --help Display help message and exit. -R, --root CHROOT_DIR Apply changes in the CHROOT_DIR directory and use the configuration files from the CHROOT_DIR directory. -t, --time DAYS Print the lastlog records more recent than DAYS. -u, --user LOGIN|RANGE Print the ...

Powershell: Get-ChildItem

List, search/find files and directories with Get-ChildItem cmdlet.

Powershell: Test-NetConnection

PS C:\Users\tuyen> get-help Test-NetConnection NAME     Test-NetConnection SYNTAX     Test-NetConnection [[-ComputerName] <string>] [-TraceRoute] [-Hops <int>] [-InformationLevel {Quiet |     Detailed}]  [<CommonParameters>]     Test-NetConnection [[-ComputerName] <string>] [-CommonTCPPort] {HTTP | RDP | SMB | WINRM}     [-InformationLevel {Quiet | Detailed}]  [<CommonParameters>]     Test-NetConnection [[-ComputerName] <string>] -Port <int> [-InformationLevel {Quiet | Detailed}]     [<CommonParameters>]     Test-NetConnection [[-ComputerName] <string>] -DiagnoseRouting [-ConstrainSourceAddress <string>]     [-ConstrainInterface <uint32>] [-InformationLevel {Quiet | Detailed}]  [<CommonParameters>] ALIASES     TNC REMARKS     Get-Help cannot find the Help files fo...