converter - Insert Header Row using sed -


i need run bash script via cron update file. file .dat (similar csv) , contains pipe separated values. need insert header row @ top.

here's have far:

#!/bin/bash # grab file, make backup , insert new line sed -i.bak 1i"red|blue|green|orange|yellow" thefilename.dat  exit 

but how can save file different file name takes filea, edits , saves fileb

do rename old 1 xxx.bak or can save new copy?

either way, use redirection.

sed 1i"red|blue|green|orange|yellow" thefilename.dat > newfile.dat

or if want .bak

 sed 1i"red|blue|green|orange|yellow" thefilename.dat > newfile.dat \ && mv thefilename.dat thefilename.dat.bak` 

which create new file , then, if sed completed sucessfully, rename orig file.


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -