# print first 10 lines of file (emulates behavior of "head") sed 10q # print first line of file (emulates "head -1") sed q # print the last 10 lines of a file (emulates "tail") sed -e :a -e '$q;N;11,$D;ba' # print the last 2 lines of a file (emulates "tail -...
1. Delete the 1st lineor the header line: $ sed '1d' file Unix Linux Solaris AIX d command is to delete a line. 1d means to delete the first line. The above command will show the file content by deleting the first line. However, the source file remains unchanged. To update the ori...
# delete trailing whitespace (spaces, tabs) from end of each line sed 's/[ \t]*$//' # see note on '\t' at end of file # delete BOTH leading and trailing whitespace from each line sed 's/^[ \t]*//;s/[ \t]*$//' # insert 5 blank spaces at beginning of each line (make...
# then delete the first line D } }' file 在前面我介绍过”=”命令,并用它向一个文件添加行号,你可以用sed的两次调用来实现(尽管可以用一次调用来实现,但这种是在下节介绍)。第一次调用是用sed输出文件行号,然后在下一行打印行内容,第二次调用会将两行合起来: #!/bin/sh sed '=' file | \ sed '...
delete text in the pattern space up to the first newline, and restart cycle with the resul- tant pattern space, without reading a new line of input.h H Copy/append pattern space to hold space.g G Copy/append hold space to pattern space.n N Read/append the next line of input into ...
addr= address of a line (number or pattern ) d= delete Examples Remove the 3rd line: sed '3d' fileName.txt Remove the line containing the string "awk": sed '/awk/d' filename.txt Remove the last line: sed '$d' filename.txt ...
If you wanted to keep the first word of a line, and delete the rest of the line, mark the important part with the parenthesis: sed 's/\([a-z]*\).*/\1/' I should elaborate on this. Regular expressions are greedy, and try to match as much as possible. "[a-z]*" matches ze...
last(1) lastcomm(1) lbxproxy(1) ld(1) ld(1g) ld.so.1(1) ld86(1) ldapadd(1) ldapdelete(1) ldaplist(1) ldapmodify(1) ldapmodrdn(1) ldapsearch(1) ldd(1) lefty(1) less(1) lessecho(1) lesskey(1) let(1) lex(1) lftp(1) lftpget(1) lgrpinfo(1) libgd2(1) libnetcfg(...
# delete lines starting from the 1st match of "Jason" until the 4th line: sed '/Jason/,4 d' xxx # sed '/Raj/,/Jane/ d' xxx # sed '/Jason/,+2 d' xxx --- # delete all empty lines from a file: sed '/^$/ d' xxx # delete all comments from a flle sed '/^#/ d' ...
$ sed '3c\This is a changed line of text.' data.txt $ sed '/number 3/c\This is a changed line of text.' data.txt d:delete(删除),删除文本流中的特定行 $ sed '3d' data.txt //删除第三行 $ sed '3,$d' data.txt //删除第三行到行末 ...