【发布时间】:2018-04-19 17:58:08
【问题描述】:
这是“file1.txt”的统计结果
`File: 'file1.txt'
Size: 477 Blocks: 8 IO Block: 4096 regular file
Device: 806h/2054d Inode: 55599980 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1000/ marc) Gid: ( 1000/
marc)
Access: 2018-04-19 19:19:01.708143285 +0200
Modify: 2018-04-19 19:18:58.216117199 +0200
Change: 2018-04-19 19:18:58.216117199 +0200
Birth: -`
我想用 grep 获取“修改”行:
`stat file1.txt | grep Modify
Modify: 2018-04-19 19:18:58.216117199 +0200`
我现在想在 file1.txt 的第一行之前插入这一行。
我会使用如下命令:
`stat file1.txt | grep Modify | sed -i '1 i\"result_of_grep"' file1.txt`,
但不知道如何告诉 shell 使用前面 grep dommand 的结果(我称之为“result_of_grep”)。
提前谢谢...
【问题讨论】:
-
为什么不在grep前面插入一行?
-
stat -c '%y' file1.txt -
不要为此使用
sed -i。只需{ stat -c '%y' file1.txt; cat file1.txt; } > file2.txt。 -
很好,谢谢。我想在我的 file1.txt 中得到有趣的行...