Copy file with changed content

Eddy

I'm writing bash script where I need to store some files as a .bak files and change it content at the beginning(using sed for that).

I'm looking for better way to write it down for my bash script.
cp file.txt file.txt.bak | sed -i '1i#Backup file' file.txt.bak

Maybe someone knew more efficient way to do this or how to do this only by sed or just without pipes.

terdon

The pipe isn't doing anything at all there. cp has no output, and therefore you cannot pipe its output to another program. I'm guessing you wanted ; or && instead:

## copy the file and then run sed
cp file.txt file.txt.bak; sed -i '1i#Backup file' file.txt.bak

Or

## copy the file and then run sed BUT only if the copy was successfull
cp file.txt file.txt.bak && sed -i '1i#Backup file' file.txt.bak

However, if all you want is a copy of the original file with the first line changed, then sed can indeed do it for you:

sed  '1i#Backup file' file.txt > file.txt.bak

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Copy file content to a string

From Dev

Copy file content to a string

From Java

copy the content of the file to other location

From Dev

Copy content of HTM file into clipboard

From Dev

Copy content of HTM file into clipboard

From Dev

Powershell copy a file or get the content without lock it

From Dev

copy file content to a buffer using rdbuf failed

From Dev

How to copy content inside of a txt file to clipboard?

From Dev

Copy header content from .doc to .xlsm file

From Dev

copy file content to the clipboard in linux terminal

From Dev

Copy CSS file content node js

From Dev

How to get content of a text file and copy it to clipboard?

From Dev

Conditionally copy content from external XML file

From Dev

Copy the entire content of a file opened in Putty to clipboard

From Dev

copy file content to a buffer using rdbuf failed

From Dev

How to copy content inside of a txt file to clipboard?

From Dev

Rsync copy only changed files; ignore file modification time stamps

From Dev

Create several copies of file with one line in each copy changed

From Dev

If a file is re-written with the same content, will the modification time be changed?

From Dev

How can I copy a file content into a temporary file in PHP?

From Dev

Gulp Copy content from one file to another file

From Dev

Copy and update content of actively recording Wav file to a new file

From Dev

copy content of file to another file using python script

From Dev

How to copy and paste indd file content into an another indd file?

From Dev

Is there any way to copy file's content in clipboard without opening the file?

From Dev

How to copy content from a text file to another text file in C

From Dev

How to copy only file attributes (metadata) without actual content of the file?

From Dev

File content copy to another file using C++

From Dev

file uploaded on ftp server didn't copy complete content

Related Related

  1. 1

    Copy file content to a string

  2. 2

    Copy file content to a string

  3. 3

    copy the content of the file to other location

  4. 4

    Copy content of HTM file into clipboard

  5. 5

    Copy content of HTM file into clipboard

  6. 6

    Powershell copy a file or get the content without lock it

  7. 7

    copy file content to a buffer using rdbuf failed

  8. 8

    How to copy content inside of a txt file to clipboard?

  9. 9

    Copy header content from .doc to .xlsm file

  10. 10

    copy file content to the clipboard in linux terminal

  11. 11

    Copy CSS file content node js

  12. 12

    How to get content of a text file and copy it to clipboard?

  13. 13

    Conditionally copy content from external XML file

  14. 14

    Copy the entire content of a file opened in Putty to clipboard

  15. 15

    copy file content to a buffer using rdbuf failed

  16. 16

    How to copy content inside of a txt file to clipboard?

  17. 17

    Rsync copy only changed files; ignore file modification time stamps

  18. 18

    Create several copies of file with one line in each copy changed

  19. 19

    If a file is re-written with the same content, will the modification time be changed?

  20. 20

    How can I copy a file content into a temporary file in PHP?

  21. 21

    Gulp Copy content from one file to another file

  22. 22

    Copy and update content of actively recording Wav file to a new file

  23. 23

    copy content of file to another file using python script

  24. 24

    How to copy and paste indd file content into an another indd file?

  25. 25

    Is there any way to copy file's content in clipboard without opening the file?

  26. 26

    How to copy content from a text file to another text file in C

  27. 27

    How to copy only file attributes (metadata) without actual content of the file?

  28. 28

    File content copy to another file using C++

  29. 29

    file uploaded on ftp server didn't copy complete content

HotTag

Archive