这是我的样本文件
user@linux:~$ cat file.txt
Line 1
Line 2
Line 3
Line 4
Line 5
user@linux:~$
我可以用grep -A2 'e 2' file.txt打印第2-4行。
user@linux:~$ grep -A2 'e 2' file.txt
Line 2
Line 3
Line 4
user@linux:~$
我也可以用grep -n打印出行号。
user@linux:~$ grep -nA2 'e 2' file.txt
2:Line 2
3-Line 3
4
如何使用sed来查找linux这个词的行?稍后会用linux这个词显示第10行吗?前:
cat file | sed -e '/linux/!d' -e '10!d' ### I can not display the first 10 lines of the word linux
cat file | sed '/linux/!d' | sed '10!d' ### It is well
如何使它与一个sed一起工作?
cat file | sed -e '/linux/!d; ...?; 10!d'
.?-
我遇到了一个问题,一个程序突然不想启动了,没有错误,什么都没有。为了确保代码及其链接库的完整性,我想比较每个(动态)链接库的md5sum。从这个论坛的其他帖子中,我发现很容易列出所有的链接库,很好地展示它们:
ldd myProgram | grep so | sed -e '/^[^\t]/ d' \
| sed -e 's/\t//' | sed -e 's/.*=..//' \
| sed -e 's/ (0.*)//'
如何添加md5sum或sha1sum,使其在文件名旁边添加一个校验和列?简单地添加md5sum只会产生一
如何在sed命令中仅替换特定值
例如,
Linux system
Windows syste
Mac syste
我试过这个命令
sed /system/system/g‘file.txt
safwanpaloli@hello:~/linx$ sed 's/syste/system/g' new.txt
Linux systemm
Windows system
Mac system
我预期的结果
Linux system
Windows system
Mac system
如何使用sed用文本替换空行?我尝试了一些早些时候发布的技巧,但它不起作用。有人能帮我吗?
示例文件内容-
Linux is an os.
Linux is opensource
Linux has various flavors like fedora,centos etc.
我想用像hello这样的文字来代替这些空白行。
我想用第一行中#之间的任何字符替换一个字符串(在本例中是单词Linux)。
所以我想转一转:
#Windows#
1. Linux Sysadmin, Linux Scripting etc.
2. Databases - Oracle, mySQL etc.
3. Security (Firewall, Network, Online Security etc)
4. Storage in Linux
5. Productivity (Too many technologies to explore, not much time available)
进入:
1. Windows Sysad
我在脚本中使用下面的代码,它应该匹配hosts.test中的"title随机Linux服务器“,并在2行匹配字符串之后将t3文件的文本插入到hosts.test中。但它带来了一些错误。
sed -i.bak '/^title AHS - zarriot CBTS random Linux Servers$/ {N;N; r t3}' hosts.test
有人能帮我吗?
我在Linux上使用这个sed命令来修补一个文件,它工作得很好:
sed -i -r "s/(\tpublic function __call.*)/\1\n\t\treturn null;/" rb.php
但是当我在OS X上尝试这个命令时,我得到了一个错误:
sed: 1: "s/(\tpublic function __ ...": \1 not defined in the RE
那么,有没有人能帮我做一个在Linux和OS上都能工作的命令呢?
顺便说一下,我尝试了如下命令:
sed -i '' -r "s/(\tpublic
我想用sed将…。中的内容替换为目标key=new_string
more /tmp/file
my.uri=http://[linux123]:8080
我们试试这个
key=new_string
sed s"/\[*\]/$key/g" /tmp/file
但文件没有更改
more file
my.uri=http://[linux123]:8080
我的苏醒怎么了?
预期结果应为(不带方括号)
more file
my.uri=http://new_string:8080