1833832 Members
2107 Online
110063 Solutions
New Discussion

Re: File copy

 
Enda martin
Occasional Contributor

File copy

is there a command within unix which will allow you to copy a certain % of the file to a new file.

EG : File a --> Copy 65% of a to give File b

8 REPLIES 8
Robin Wakefield
Honored Contributor

Re: File copy

Hi Enda,

I assume you mean text files - which section of the file do you want to copy, e,g, the first 65% or the last 65%?

Rgds, Robin.
Enda martin
Occasional Contributor

Re: File copy

the % of the split is not really important - the original file (file a) is to large to manipulate as is so I just need to split it into two smaller files - so therefore say a 50-50 split

Rainer von Bongartz
Honored Contributor

Re: File copy

to copy the first xyz bytes from a to b use

head -c -n xyz a > b

to copy the last xyz bytes from a to b use

tail - c xyz a > b
He's a real UNIX Man, sitting in his UNIX LAN making all his UNIX plans for nobody ...
Rainer von Bongartz
Honored Contributor

Re: File copy

so why not use the split command in this case???

see man split

Regards
Rainer


He's a real UNIX Man, sitting in his UNIX LAN making all his UNIX plans for nobody ...
Robin Wakefield
Honored Contributor

Re: File copy

Enda,

OK - have a look at the split command - you can tell it how many ways to split, or how big each output file should be.

The problem with tail is that it's not good at handling a large tail of a big file.

Rgds, Robin
Stefan Schulz
Honored Contributor

Re: File copy

Hi,

there is also th command csplit which allows you to use searchpatterns. So you could use for example a specific date or time in a logfile as the splitposition.

Have a look at man csplit.

Hope this helps.

Regards Stefan
No Mouse found. System halted. Press Mousebutton to continue.
MANOJ SRIVASTAVA
Honored Contributor

Re: File copy

try split.


Manoj
harry d brown jr
Honored Contributor

Re: File copy

Use the "dd" command, here is a very "rude" example, and can probably be cut down to something smaller:

echo `ls -l fileA`"\nx x x x .65" | tr -s " " " " | cut -d" " -f 5 | xargs echo | sed "s/ / \* /g" | bc | cut -d"." -f1 | sed "s/$/ \/ 512 /" | bc | sed "s:^:dd if=fileA of=fileB count=:"|sh

replace the .65 with whatever percent you want.
Live Free or Die