Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Prepending header line to HUGE csv file

by graff (Chancellor)
on Oct 31, 2015 at 05:15 UTC ( [id://1146555]=note: print w/replies, xml ) Need Help??


in reply to Prepending header line to HUGE csv file

Here's the fastest way I know of to prepend a line at the beginning of any file, regardless of its size. It involves the *n*x shell commands "echo" and "cat":
echo "This is the new first line" | cat - big.file > new.big.file
Of course, if the line to be prepended is really long or complicated, you can use a text editor or other method to create a small file containing just that first line (e.g. a file called "new.first.line"), and do this:
cat new.first.line big.file > new.big.file
I'm pretty sure there's no faster way it can be done. Of course, speed varies according to things like: Is the output being written to a local disk, or some sort of remote, network-mounted disk? (local storage is much faster) What sort of file system is it? ("Journaled" file systems might be slower), etc.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1146555]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-04-19 05:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found