본문 바로가기

Hojung's Command List

Total Commands : 232

 (e)grep (6)
 * find large files (2)
 * System info (12)
 * Term Key (8)
 * use previous argu (1)
 *CD/DVD cmd (5)
 *DNS test (4)
 ab (2)
 apg (1)
 arping (4)
 at (1)
 awk (1)
 cal (2)
 cd and pushd (3)
 crontab (7)
 curl (4)
 dd (1)
 dhclient (1)
 dig (2)
 du (1)
 echo (1)
 editcap (1)
 ethtool (2)
 find (20)
 head (1)
 history (1)
 host (1)
 hping3 (6)
 ifconfig (3)
 lftp (1)
 logger (1)
 ls (2)
 lsof (2)
 mail (2)
 man (1)
 mergecap (1)
 mount (8)
 nc (netcat) (1)
 ncftpput (1)
 netcat(nc) (1)
 netstat (1)
 nice (2)
 nl (1)
 nmap (5)
 ntpdate (1)
 openssl (15)
 ping (1)
 pkill (1)
 ps (2)
 rar (1)
 recode (6)
 rename (3)
 rm (1)
 route (2)
 rpm (4)
 sed (4)
 smb (3)
 snmpwalk (2)
 sort (4)
 ssh (1)
 tar (6)
 tcpdump (10)
 top (1)
 touch (2)
 uniq (1)
 vi (11)
 wall (2)
 wget (3)
 yum (5)
 zip/unzip (6)

Use variable for pattern in sed

pattern='^test$'
safe_pattern=$(printf "%s" "$pattern" | sed 's/[][\.*^$/]/\\&/g')
sed "s/${safe_pattern}/test/g" file.txt

from......
$ safe_pattern=$(printf "%s\n" "$pattern" | sed 's/[][\.*^$/]/\\&/g')
# now you can safely do
$ sed "s/${safe_pattern}/FOOBAR/g" file.txt
$ sed -n "/${safe_pattern}/p" file.txt
Written by Hojung at 2012-03-16 18:50:49

known_hosts의 public key 삭제

sed -i -e '/1.1.1.1.*$/d' /home/user/.ssh/known_hosts

Written by Hojung at 2011-07-22 17:34:06

sed를 이용해 'Wide character in print at xxxxx' 행 삭제

sed -i -e '/Wide.*$/d' text.txt

Written by Hojung at 2011-07-12 20:21:41

Text 파일의 내용 변경하기 (단일 파일 또는 여러 파일)

sed -i 's/foo/foo_bar/g' somefile.module
sed -i 's/foo/foo_bar/g' *.module <----- 여러 파일 변경 가능

* -i = edit the file "in-place": sed will directly modify the file if it finds anything to replace
* s = substitute the following text
* foo = the text string to be substituted
* foo_bar = the replacement string
* g = global, match all occurrences in the line
Written by Hojung at 2010-10-05 18:18:38