I have a file which looks like this:
file1
file2
file3
.
.
.
filen
I want to convert it to :
echo "file1"
cat file1
echo "file2"
cat file2
.
.
.
.
echo "filen"
cat filen
One way can be to have a for loop and read the content of original file and write modified content to another file , I did that and it worked. Is there any command to do the same in vim
through :g
or any other command?
Try this:
:%s/.*/echo "\0"\rcat \0/g
Explanation:
:%s/a/b/g
means search whole file and replace a
to b
.
.*
means match every thing in one line.
\0
means the matched thing.
\r
means the new line.