1855240 Members
4199 Online
104109 Solutions
New Discussion

Trimming filles

 
SOLVED
Go to solution
Fabian Briseño
Esteemed Contributor

Trimming filles

Hi guys.

Is there any was ti trim a file let's say the file is 1MB and i want to trimit to 500kb, I know that this could be done via SAM, but is there a way to do it via command line.

Knowledge is power.
5 REPLIES 5
Jaime Bolanos Rojas.
Honored Contributor
Solution

Re: Trimming filles

Fabian,

This thread should help you out,

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1033864

Regards,

Jaime.
Work hard when the need comes out.
Pete Randall
Outstanding Contributor

Re: Trimming filles

tail -500 file > file2
mv file2 file


Pete

Pete
Peter Godron
Honored Contributor

Re: Trimming filles

Fabian,
As a one off:
either
use vi or tail -xxxxx > tempfile
or
split the file into chunks the size you want then cp the final split to the original file.
see man split

For the more elegant solution I'd stick to SAM.
James R. Ferguson
Acclaimed Contributor

Re: Trimming filles

Hi Fabian:

If we assume that you are talking about ASCII files, 'sed' or 'perl' are easily leveraged. For instance, consider a 1000-line file where you want to preserve only the last 500 lines:

# sed -ne '501,$p' file

With Perl:

# perl -ni -e 'print if $. > 501'

The perl script will update your file "in-place' leaving a trimmed copy.

Regards!

...JRF...
Fabian Briseño
Esteemed Contributor

Re: Trimming filles

thanks guys you were of great help.

Knowledge is power.