欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

Linux下sed命令的用法介紹

這篇文章主要講解了“Linux下sed命令的用法介紹”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“Linux下sed命令的用法介紹”吧!

這篇文章主要講解了“Linux下sed命令的用法介紹”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“Linux下sed命令的用法介紹”吧!

創(chuàng)新互聯(lián)長期為數(shù)千家客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊從業(yè)經(jīng)驗10年,關(guān)注不同地域、不同群體,并針對不同對象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺,與合作伙伴共同營造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為東山企業(yè)提供專業(yè)的做網(wǎng)站、成都網(wǎng)站建設(shè)東山網(wǎng)站改版等技術(shù)服務(wù)。擁有10年豐富建站經(jīng)驗和眾多成功案例,為您定制開發(fā)。

Linux sed命令詳細(xì)說明

sed是一種用于過濾和轉(zhuǎn)換文本的流編輯器。用于對輸入流(文件或來自管道的輸入)執(zhí)行基本文本轉(zhuǎn)換。

雖然sed在某些方面類似于允許腳本編輯(如ed)的編輯器,但它的工作方式是只傳遞一次輸入,因此效率更高。

思考:

查看當(dāng)前IP

[root@cjcos01 cjc]# ifconfig

通過ifconfig雖然可以查看IP,但是打印出很多并不關(guān)注的信息,如何去掉這部分無用的信息?

可以通過sed加grep實現(xiàn),方法見后面的示例。

測試數(shù)據(jù)

[root@cjcos01 cjc]# cat t1.txt 

tao花庵歌tao花塢里tao花庵,tao花庵下tao花仙;tao花仙人種tao樹,又摘tao花賣酒錢。酒醒只在花前坐,酒醉還來花下眠;半醒半醉日復(fù)日,花落花開年復(fù)年。但愿老死花酒間,不愿鞠躬車馬前;車塵馬足富者趣,酒盞花枝貧者緣。若將富貴比貧賤,一在平地一在天;若將貧賤比車馬,他得驅(qū)馳我得閑。別人笑我太瘋癲,我笑他人看不穿;不見五陵豪杰墓,無花無酒鋤作田。

1 打印行

打印第二行 

[root@cjcos01 cjc]# sed -n '2p' /cjc/t1.txt

tao花塢里tao花庵,tao花庵下tao花仙;

打印第2-5行

[root@cjcos01 cjc]# sed -n '2,5p' /cjc/t1.txt

tao花塢里tao花庵,tao花庵下tao花仙;tao花仙人種tao樹,又摘tao花賣酒錢。酒醒只在花前坐,酒醉還來花下眠;半醒半醉日復(fù)日,花落花開年復(fù)年。

打印第10行到結(jié)尾行

[root@cjcos01 cjc]# sed -n '10,$p' /cjc/t1.txt

別人笑我太瘋癲,我笑他人看不穿;不見五陵豪杰墓,無花無酒鋤作田。

打印第2行,第6行,第8,9,10行

[root@cjcos01 cjc]# sed -n '2p;6p;8,10p' /cjc/t1.txt

tao花塢里tao花庵,tao花庵下tao花仙;但愿老死花酒間,不愿鞠躬車馬前;若將富貴比貧賤,一在平地一在天;若將貧賤比車馬,他得驅(qū)馳我得閑。別人笑我太瘋癲,我笑他人看不穿;

打印含有tao字的行

[root@cjcos01 cjc]# sed -n '/tao/p' /cjc/t1.txt 

tao花庵歌tao花塢里tao花庵,tao花庵下tao花仙;tao花仙人種tao樹,又摘tao花賣酒錢。

打印"酒"字開頭的行

[root@cjcos01 cjc]#  sed -n '/^酒/p' /cjc/t1.txt 

酒醒只在花前坐,酒醉還來花下眠;

打印"。"結(jié)尾的行

[root@cjcos01 cjc]#  sed -n '/\。$/p' /cjc/t1.txt 

tao花仙人種tao樹,又摘tao花賣酒錢。半醒半醉日復(fù)日,花落花開年復(fù)年。車塵馬足富者趣,酒盞花枝貧者緣。若將貧賤比車馬,他得驅(qū)馳我得閑。不見五陵豪杰墓,無花無酒鋤作田。

2 插入行

[root@cjcos01 cjc]# cp t1.txt t1.txt.bak

人為多愁少年老,花為無愁老少年。年老少年都不管,且將詩酒醉花前。

行前添加,寫入源文件

[root@cjcos01 cjc]# sed -i '2i 人為多愁少年老,花為無愁老少年。' /cjc/t1.txt

[root@cjcos01 cjc]# cat t1.txt

tao花庵歌人為多愁少年老,花為無愁老少年。tao花塢里tao花庵,tao花庵下tao花仙;......

行后添加(直接修改原文件)

[root@cjcos01 cjc]# sed -i '2a 年老少年都不管,且將詩酒醉花前。' /cjc/t1.txt

[root@cjcos01 cjc]# cat t1.txt

tao花庵歌人為多愁少年老,花為無愁老少年。年老少年都不管,且將詩酒醉花前。tao花塢里tao花庵,tao花庵下tao花仙;......

3 替換行(直接修改原文件) 

[root@cjcos01 cjc]# sed -i '2c 閑來寫就青山賣,不使人間造孽錢。' /cjc/t1.txt

[root@cjcos01 cjc]# cat t1.txt

tao花庵歌閑來寫就青山賣,不使人間造孽錢。年老少年都不管,且將詩酒醉花前。......

4 替換字符 

-n 's/old/new/p' 將文件中每行的第一個old字符換成new字符,打印出只發(fā)生變化的行,且源文件內(nèi)容不變

[root@cjcos01 cjc]# sed -n 's/tao/荷/p' /cjc/t1.txt 

荷花庵歌荷花塢里tao花庵,tao花庵下tao花仙;荷花仙人種tao樹,又摘tao花賣酒錢。

-n 's/old/new/pg':將文件中全部的old字符換成new字符,打印出只發(fā)生變化的行,且源文件內(nèi)容不變。

[root@cjcos01 cjc]# sed -n 's/tao/荷/pg' /cjc/t1.txt 

荷花庵歌荷花塢里荷花庵,荷花庵下荷花仙;荷花仙人種荷樹,又摘荷花賣酒錢。

-n 's/old/new/p3g' :將文件中每行從第3個old字符開始換成new字符,打印出只發(fā)生變化的行,且源文件內(nèi)容不變

[root@cjcos01 cjc]# sed -n 's/tao/荷/p3g' /cjc/t1.txt 

tao花塢里tao花庵,荷花庵下荷花仙;tao花仙人種tao樹,又摘荷花賣酒錢。

-i,將文件中每行的第一個old字符換成new字符,修改源文件內(nèi)容

[root@cjcos01 cjc]# sed -i 's/tao/荷/g' /cjc/t1.txt 

[root@cjcos01 cjc]# sed -i 's/荷/tao/g' /cjc/t1.txt 

5 刪除行

刪除第2行

[root@cjcos01 cjc]# sed -i '2d' /cjc/t1.txt

刪除第3到5行

[root@cjcos01 cjc]# sed -i '3,5d' /cjc/t1.txt

刪除第2行,第4,5,6行

[root@cjcos01 cjc]# sed -i '2d;4,6d' /cjc/t1.txt

舉例:

例1: 只顯示ifconfig中的IP地址

[root@cjcos01 ~]# ifconfig |grep "inet"|grep -v "inet6"|grep -v "127.0.0.1"|grep -v "122.1"|sed 's/netmask.*//'|sed 's/^.*inet//' 192.168.38.10

例2:去掉ssh配置文件中的帶#行和空行,不修改源文件,將結(jié)果打印到前臺

[root@cjcos01 cjc]# echo >t1.txt

[root@cjcos01 cjc]# cat /etc/ssh/ssh_config > t1.txt

[root@cjcos01 cjc]# sed 's/#.*//g' /cjc/t1.txt |sed '/^$/d'

Host *GSSAPIAuthentication yesForwardX11Trusted yesSendEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGESSendEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENTSendEnv LC_IDENTIFICATION LC_ALL LANGUAGESendEnv XMODIFIERS

例3:每一行結(jié)尾為.的換成!("."需要加轉(zhuǎn)義符),不改變源文件(指定-i會改變源文件)

[root@cjcos01 cjc]# sed -n 's/\.$/!/p' /cjc/t1.txt

GSSAPIAuthentication yes!ForwardX11Trusted yes!SendEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT!

例4:以H開頭的行末尾加上@@@

[root@cjcos01 cjc]# sed -n 's/^H.*$/&@@@/p' /cjc/t1.txt 

Host *@@@

sed幫助信息:

[root@cjcos01 ~]# sed --helpUsage: sed [OPTION]... {script-only-if-no-other-script} [input-file]...  -n, --quiet, --silent                 suppress automatic printing of pattern space  -e script, --expression=script                 add the script to the commands to be executed  -f script-file, --file=script-file                 add the contents of script-file to the commands to be executed  --follow-symlinks                 follow symlinks when processing in place  -i[SUFFIX], --in-place[=SUFFIX]                 edit files in place (makes backup if SUFFIX supplied)  -c, --copy                 use copy instead of rename when shuffling files in -i mode  -b, --binary                 does nothing; for compatibility with WIN32/CYGWIN/MSDOS/EMX (                 open files in binary mode (CR+LFs are not treated specially))  -l N, --line-length=N                 specify the desired line-wrap length for the `l' command  --posix                 disable all GNU extensions.  -r, --regexp-extended                 use extended regular expressions in the script.  -s, --separate                 consider files as separate rather than as a single continuous                 long stream.  -u, --unbuffered                 load minimal amounts of data from the input files and flush                 the output buffers more often  -z, --null-data                 separate lines by NUL characters  --help                 display this help and exit  --version                 output version information and exitIf no -e, --expression, -f, or --file option is given, then the firstnon-option argument is taken as the sed script to interpret.  Allremaining arguments are names of input files; if no input files arespecified, then the standard input is read.GNU sed home page: <http://www.gnu.org/software/sed/>.General help using GNU software: <http://www.gnu.org/gethelp/>.E-mail bug reports to: <bug-sed@gnu.org>.Be sure to include the word ``sed'' somewhere in the ``Subject:'' field.[root@cjcos01 ~]# man sedNAME       sed - stream editor for filtering and transforming textSYNOPSIS       sed [OPTION]... {script-only-if-no-other-script} [input-file]...DESCRIPTION       Sed  is  a stream editor.  A stream editor is used to perform basic text transformations       on an input stream (a file or input from a pipeline).  While in some ways similar to  an       editor which permits scripted edits (such as ed), sed works by making only one pass over       the input(s), and is consequently more efficient.  But it is  sed's  ability  to  filter       text in a pipeline which particularly distinguishes it from other types of editors.......SEE ALSO       awk(1), ed(1), grep(1), tr(1), perlre(1), sed.info, any of various books on sed, the sed       FAQ (http://sed.sf.net/grabbag/tutorials/sedfaq.txt), http://sed.sf.net/grabbag/.       The full documentation for sed is maintained as a Texinfo manual.  If the info and sed       programs are properly installed at your site, the command              info sed[root@cjcos01 ~]# info sedFile: sed.info,  Node: Top,  Next: Introduction,  Up: (dir)sed, a stream editor********************This file documents version 4.2.2 of GNU `sed', a stream editor.......

新聞標(biāo)題:Linux下sed命令的用法介紹
鏈接地址:http://aaarwkj.com/article16/jegg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供搜索引擎優(yōu)化、靜態(tài)網(wǎng)站、App開發(fā)、定制開發(fā)、建站公司、網(wǎng)站維護(hù)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站托管運營
99久久精品国产熟女| 免费人成视频在线观看不卡| 午夜精品久久福利视频| 国产自拍在线视频精品| 亚洲国产欧美一区三区成人| 欧美两性色一区二区三区| 天天操天天日天天射夜夜爽| 肥胖老熟女一区二区三区| 午夜高清影院免费观看| 日本少妇激情后入嗯啊| 亚洲国产日韩欧美在线播放| 亚洲码av一区二区三区| 中文字幕有码av海量| 亚洲中文字幕女同系列av专区| 一区二区三区四区毛片| 日韩欧美国产精品加勒比 | 日本高清不卡免费在线观看视频一二三区 | av电影网站中文字幕| 日韩亚洲中文一区三级黄片| 欧美日韩一级一区二区| 亚洲精品欧美激情专区| 亚洲一区二区三区精品日韩| 99久久久精品国产免费| 欧美乱码中文字幕在线观看| 日本色网一区二区三区四区 | 色婷婷综合中文久久一本| 尤物视频在线观看羞羞| 亚洲一区二区三区免费在线视频| 欧美成人精品资源在线观看| 日韩精品视频一区二区在线观看| 亚洲人妻av一区二区三区| 国产黄色免费精品网站| 日本师生三片在线观看| 亚洲成av人天堂影院| 亚洲av资源一区二区| 亚洲综合国产一二三四五区| 亚洲欧美日韩国产成人精品| 性生活的视频免费观看麻豆| 国产超大超粗超爽视频| 中文字幕国产成人在线视频| 日本韩国精品视频在线|