sed常见用法总结
编辑文本 sed -i 1i xyz test.txt 在第一行之前sed -i 1a xyz test.txt 在第一行之后插入sed -i 1c xyz test.txt 把第一行数据替换成xyzsed /^bb/i\kjdlfkjdslkf temp.txt //在匹配的行之前加入新一行sed /^bb/a\kjdlfkjdslkf temp.txt //在匹配的行之后加入
编辑文本 sed -i '1i xyz' test.txt 在第一行之前 sed -i '1a xyz' test.txt 在第一行之后插入 sed -i '1c xyz' test.txt 把第一行数据替换成xyz sed '/^bb/i\kjdlfkjdslkf' temp.txt //在匹配的行之前加入新一行 sed '/^bb/a\kjdlfkjdslkf' temp.txt //在匹配的行之后加入新行 sed -n '/xxx/w temp.txt' temp1.txt //temp1.txt中匹配xxx的行插入到temp.txt sed '/xx/c\sdfdsf' temp.txt //用新的一行数据替换匹配xx的行 sed '1d' t.txt /删除文件第一行 sed '/bro/d' t.txt //删除带bro的行 (实际修改,删除等加-i) sed '/^$/d' t.txt //删除空行 sed 's/^.*uid//' t.txt //将uid前这段字符替换成空,^第一个字符不能为*,要加.,另外在sed里字符与*连接要加. sed 's/night/NIGHT/' 1.TXT //将night替换 (加 -i 直接修改源文件1.txt,而不是将替换后的数据输出到屏幕) sed 's/night/NIGHT/g' 1.TXT 替换所有,不加g一行只替换一次 sed 's/.html//' b.txt >b0.txt sed 'y/bo/BO/' test.txt //将b替换成B,o替换成O sed 'y/bb ll/BB LL/' test.txt //将bb替换成BB,ll替换成LL 查询文本 sed '/he/w test1.txt' test.txt //读取test.txt内容匹配he的行写入test1.txt sed '1,2w test1.txt' test.txt //读取test.txt内容,第一二行写入test1.txt sed '/he/r test1.txt' test.txt //读取test.txt内容匹配he的行与test1.txt所有内容合并后输出 sed -n '1,3p' getrow.sh //显示一行到三行的肉容 sed -n '1,/hello/'p orig.txt //从第一行开始打印,打印到第一个含有hello行 //n的作用是取消默认输出 只打印包含模板的行,缺省为打印所有行(编辑和未编辑) sed -n '$p' getrow.sh //最后一行 sed -n '/echo/'p while.sh //打印包括echo字符的行 /pattern/模式 sed -e '/echo/=' while.sh //并且打印行号(并且整个文件都打印) -n 只打印实际行号 打印行号使用= sed -n -e '/dfs.support.append/=' hdfs-default.xml sed -n -e '/we/p' -e '/we/=' 2.txt //只打印匹配的行,并行显示行号 sed -n '/aa/=' aa.txt //只显示匹配上的行号 sed -n '/^h/'p test.txt //显示h为开头的行 sed '/^hello/d' test.txt //查询非某某开头的写法 sed -n '/s\{2,\}/'p test.txt //s字符至少匹配两次 sed -n '/[0-9]\{1,\}/'p test.txt //包含数字的行,用[0-9]+不支持 sed '2q' test.txt //打印到第二行退出 需要注意的是,sed并不直接操作初始数据,它操作的是一份原始数据的拷贝。sed处理时,把当前处理的行存储在临时缓冲区中,然后处理缓冲区中的内容,处理完成后,如果没有重定向到文件, 将把缓冲区中的内容送往屏幕,接着处理下一行直到处理完毕

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Does anyone know how to edit documents in Tencent Docs? It doesn't matter if you don't know. Today, the editor will introduce detailed graphic explanations on how to edit documents in Tencent Docs. I hope it can help you. Detailed graphic explanation of editing documents in Tencent Documents 1. First, enter Tencent Documents directly (if you don’t have it, download it now!) and log in directly (QQ and TIM two login methods are supported) 2. After logging in, click Add in the upper right corner No., directly create online documents, online forms, new folders, etc.! 3. Then enter the information according to your needs!

When processing files under Linux systems, it is sometimes necessary to delete lines at the end of the file. This operation is very common in practical applications and can be achieved through some simple commands. This article will introduce the steps to quickly delete the line at the end of the file in Linux system, and provide specific code examples. Step 1: Check the last line of the file. Before performing the deletion operation, you first need to confirm which line is the last line of the file. You can use the tail command to view the last line of the file. The specific command is as follows: tail-n1filena

Summary of the system() function under Linux In the Linux system, the system() function is a very commonly used function, which can be used to execute command line commands. This article will introduce the system() function in detail and provide some specific code examples. 1. Basic usage of the system() function. The declaration of the system() function is as follows: intsystem(constchar*command); where the command parameter is a character.

Classification and Usage Analysis of JSP Comments JSP comments are divided into two types: single-line comments: ending with, only a single line of code can be commented. Multi-line comments: starting with /* and ending with */, you can comment multiple lines of code. Single-line comment example Multi-line comment example/**This is a multi-line comment*Can comment on multiple lines of code*/Usage of JSP comments JSP comments can be used to comment JSP code to make it easier to read

Title: How to restore the hosts file after deletion Summary: The hosts file is a very important file in the operating system and is used to map domain names to IP addresses. If you accidentally delete the hosts file, you may be unable to access certain websites or have other network problems. This article will introduce how to recover accidentally deleted hosts file in Windows and Mac operating systems. Text: 1. Restore hosts file in Windows operating system. Hosts file in Windows operating system

This tutorial shows you how to find specific text or phrases on all open tabs in Chrome or Edge on Windows. Is there a way to do a text search on all open tabs in Chrome? Yes, you can use a free external web extension in Chrome to perform text searches on all open tabs without having to switch tabs manually. Some extensions like TabSearch and Ctrl-FPlus can help you achieve this easily. How to search text across all tabs in Google Chrome? Ctrl-FPlus is a free extension that makes it easy for users to search for a specific word, phrase or text across all tabs of their browser window. This expansion

Apple allows you to quickly change your home screen by rearranging your home screen pages at any time and deleting them freely. This way, you can easily hide multiple apps and widgets without dragging and deleting them one by one. In this article, we will explain how to edit pages on your iPhone home screen. CONTENTS[SHOW] Shows how to edit Home screen pages on iPhone You can edit the Home screen to rearrange pages, hide/unhide certain pages in the Home screen, and delete pages completely. To start editing your iPhone home screen, press and hold an empty area on your home screen. When your home screen enters jitter mode, tap the row of dots at the bottom of the screen. You should now see all your home screens displayed in a grid format. Option 1: On the home screen

WPS is a commonly used office software suite, and the WPS table function is widely used for data processing and calculations. In the WPS table, there is a very useful function, the DATEDIF function, which is used to calculate the time difference between two dates. The DATEDIF function is the abbreviation of the English word DateDifference. Its syntax is as follows: DATEDIF(start_date,end_date,unit) where start_date represents the starting date.
