marc
marc

Reputation: 413

grep pipe sed commands

Here is the stat result for "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: -`

I want to get the "Modify" line with grep:

`stat file1.txt | grep Modify
Modify: 2018-04-19 19:18:58.216117199 +0200`

I would like now to insert this line before first line of file1.txt.

I would use a command like:

`stat file1.txt | grep Modify | sed -i '1 i\"result_of_grep"' file1.txt`,

but don't know how to tell the shell to use the result of the preceding grep dommand (what i called "result_of_grep").

Thanks in advance...

Upvotes: 1

Views: 163

Answers (1)

anubhava
anubhava

Reputation: 785721

You can do:

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

Upvotes: 1

Related Questions