grep管道sed命令

时间:2018-04-19 17:58:08

标签: bash sed grep pipe

以下是" 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")。

提前致谢...

1 个答案:

答案 0 :(得分:1)

你可以这样做:

sed -i "1i\\
#$(stat file1.txt | grep Modify)
" file1.txt
相关问题