×ðÁú¿­Ê±¹ÙÍøµÇ¼

ÔõÑùÔÚLinuxÖÐʹÓÃsedÏÂÁî¾ÙÐÐÈÕÖ¾ÆÊÎöºÍ´¦Àí£¿

ÔõÑùÔÚlinuxÖÐʹÓÃsedÏÂÁî¾ÙÐÐÈÕÖ¾ÆÊÎöºÍ´¦Àí£¿

СÐò£º

ÔÚLinuxϵͳÖÐ £¬ÈÕÖ¾Îļþ¼Í¼ÁËϵͳµÄÔËÐÐÇéÐκÍÔËÐÐÈÕÖ¾ £¬¹ØÓÚϵͳÖÎÀíÔ±À´Ëµ £¬¶ÔÈÕÖ¾Îļþ¾ÙÐÐÆÊÎöºÍ´¦ÀíÊǺÜÊÇÖ÷ÒªµÄ¡£ÆäÖÐ £¬sedÏÂÁîÊÇÒ»ÖÖºÜÊÇÇ¿Ê¢µÄÎı¾´¦Àí¹¤¾ß £¬¿ÉÒÔÔÚLinuxÇéÐÎÖжÔÈÕÖ¾Îļþ¾ÙÐиßЧµÄÆÊÎöºÍ´¦Àí¡£±¾ÎĽ«ÏÈÈÝÔõÑùʹÓÃsedÏÂÁî¾ÙÐÐÈÕÖ¾µÄÆÊÎöºÍ´¦Àí £¬²¢ÌṩһЩ³£ÓõÄsedÏÂÁîʾÀý¡£

Ò»¡¢Ê²Ã´ÊÇsedÏÂÁ

sed£¨Stream Editor£©ÊÇÒ»ÖÖÁ÷ʽÎı¾±à¼­Æ÷ £¬Ö÷ÒªÓÃÓÚ¶ÔÎı¾¾ÙÐÐÁ÷ʽ±à¼­¡¢Ìæ»»ºÍת»»¡£ÔÚLinuxϵͳÖÐ £¬sedÊÇ´¦ÀíÎı¾ÎļþÖÐÄÚÈݵÄÒ»ÖÖÇ¿Ê¢¹¤¾ß £¬¿ÉÒÔµÖ´ïÅúÁ¿Ìæ»»¡¢É¾³ý¡¢Ìí¼ÓµÈÄ¿µÄ¡£

¶þ¡¢sedÏÂÁîµÄ»ù±¾Ê¹Óãº

sedÏÂÁî¿ÉÒÔͨ¹ýÒÔÏ·½·¨Ê¹Óãº

sed [option] 'command' file

µÇ¼ºó¸´ÖÆ

ÆäÖÐ £¬optionΪsedÏÂÁîµÄÑ¡Ïî £¬commandΪҪִÐеÄsedÏÂÁî £¬fileΪҪ´¦ÀíµÄÎļþÃû¡£

Èý¡¢³£ÓõÄsedÏÂÁ

Ìæ»»ÏÂÁîs£º

Ìæ»»ÏÂÁîsÊÇsedÏÂÁîÖÐ×î³£ÓõÄÏÂÁî £¬ÓÃÓÚÔÚÎļþÖвéÕÒ²¢Ìæ»»Ö¸¶¨µÄÎı¾¡£

sed 's/old_text/new_text/g' file

µÇ¼ºó¸´ÖÆ

ÆäÖÐ £¬old_textΪҪ²éÕÒµÄÎı¾ £¬new_textΪҪÌæ»»µÄÐÂÎı¾ £¬gÌåÏÖÈ«¾ÖÌæ»»¡£

ɾ³ýÏÂÁîd£º

ɾ³ýÏÂÁîd¿ÉÒÔɾ³ýÖ¸¶¨µÄÐС£

sed 'nd' file

µÇ¼ºó¸´ÖÆ

ÆäÖÐ £¬nΪҪɾ³ýµÄÐкÅ¡£

²åÈëÏÂÁîi£º

²åÈëÏÂÁîi¿ÉÒÔÔÚÖ¸¶¨µÄÐÐÇ°²åÈëеÄÎı¾¡£

sed 'ni
ew_text' file

µÇ¼ºó¸´ÖÆ

ÆäÖÐ £¬nΪҪ²åÈëµÄÐкŠ£¬new_textΪҪ²åÈëµÄÐÂÎı¾¡£

×·¼ÓÏÂÁîa£º

×·¼ÓÏÂÁîa¿ÉÒÔÔÚÖ¸¶¨µÄÐкó×·¼ÓеÄÎı¾¡£

sed 'na
ew_text' file

µÇ¼ºó¸´ÖÆ

ÆäÖÐ £¬nΪҪ׷¼ÓµÄÐкŠ£¬new_textΪҪ׷¼ÓµÄÐÂÎı¾¡£

Êä³öÏÂÁîp£º

Êä³öÏÂÁîp¿ÉÒÔÏÔʾָ¶¨ÐлòÖ¸¶¨Îı¾¡£

sed -n 'np' file

µÇ¼ºó¸´ÖÆ

ÆäÖÐ £¬nΪҪÏÔʾµÄÐкÅ¡£

ËÄ¡¢Ê¹ÓÃsedÏÂÁî¾ÙÐÐÈÕÖ¾ÆÊÎöºÍ´¦ÀíµÄʾÀý£º

ͳ¼ÆÈÕÖ¾ÖзºÆðij¸öÒªº¦×ÖµÄÐÐÊý£º

sed -n '/keyword/p' logfile | wc -l

µÇ¼ºó¸´ÖÆ

½«ÈÕÖ¾ÖеÄʱ¼äÃûÌÃͳһ£º

sed 's/[0-9][0-9]:[0-9][0-9]:[0-9][0-9]/[hh:mm:ss]/g' logfile

µÇ¼ºó¸´ÖÆ

ɾ³ýÈÕÖ¾ÖеĿÕÐУº

sed '/^$/d' logfile

µÇ¼ºó¸´ÖÆ

½áÂÛ£º

ÔÚLinuxÇéÐÎÖÐ £¬Ê¹ÓÃsedÏÂÁî¿ÉÒÔ¶ÔÈÕÖ¾Îļþ¾ÙÐиßЧµÄÆÊÎöºÍ´¦Àí¡£±¾ÎÄÏÈÈÝÁËsedÏÂÁîµÄ»ù±¾Ê¹Óà £¬²¢ÌṩÁËһЩ³£ÓõÄsedÏÂÁîʾÀý £¬¹©¶ÁÕ߲ο¼¡£Í¨¹ýÎÞаÔËÓÃsedÏÂÁî £¬¿ÉÒÔ´ó´óÌá¸ß¶ÔÈÕÖ¾ÎļþµÄ´¦ÀíЧÂÊ £¬ÊµÏÖÈÕÖ¾µÄÆÊÎöºÍ´¦ÀíÄ¿µÄ¡£Ï£Íû±¾ÎĶԶÁÕßÄÜÓÐËù×ÊÖú¡£

ÒÔÉϾÍÊÇÔõÑùÔÚLinuxÖÐʹÓÃsedÏÂÁî¾ÙÐÐÈÕÖ¾ÆÊÎöºÍ´¦Àí£¿µÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí £¬°æȨÕùÒéÓë±¾Õ¾ÎÞ¹Ø £¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±¹ÙÍøµÇ¼ÂËÓÍ»úÍø¹Ù·½Ì¬¶È £¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ £¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢ £¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢ £¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼

13452372176

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎå £¬9:30-18:30 £¬½ÚãåÈÕÐÝÏ¢

QR code
ÍøÕ¾µØͼ