在一堆行中添加一些文本 [英] add some text to a bunch of lines

查看:57
本文介绍了在一堆行中添加一些文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

第一个命令确实按预期工作,但第二个命令没有.我想在开头或结尾添加一些文字.

The first command does work as expected but not the second one. I want to add some text either at the beginning or the end.

# grep `date +'%y%m%d'` /var/log/mysqld.log
100101 10:56:00  mysqld started
100101 10:56:02  InnoDB: Started; log sequence number 1 2052750649

# sed 's/^/computer /g' < grep `date +'%y%m%d'` /var/log/mysqld.log
bash: grep: No such file or directory

# expected output
computer 100101 10:56:00  mysqld started
computer 100101 10:56:02  InnoDB: Started; log sequence number 1 2052750649

推荐答案

当您使用输入重定向编写它时,它会在当前目录中查找名为 grep 的文件并尝试读取它的内容,而不是执行它.您需要改用管道:

As you wrote it with input redirection, it looks for a file called grep in the current directory and tries to read its contents, not execute it. You need to use a pipe instead:

grep `date +'%y%m%d'` /var/log/mysqld.log | sed 's/^/computer /'

我还从您的 sed 中删除了g"修饰符,因为它完全没有必要.

I also removed the 'g' modifier from your sed as it is completely unnecessary.

这篇关于在一堆行中添加一些文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆