LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-28-2003, 11:38 PM   #1
sureshbabu
LQ Newbie
 
Registered: Oct 2003
Posts: 1

Rep: Reputation: 0
Question how to use truncate




Hai Buddies

I am new bie to Perl scripting.

I have to maintain a file of certain size say 5 lines if it exceeds the limit
then i hve to truncate the remaining part

How can i achive this using perl scripting

reply me

suresh
 
Old 10-29-2003, 04:22 AM   #2
yapp
Member
 
Registered: Apr 2003
Location: Netherlands
Distribution: SuSE (before: Gentoo, Slackware)
Posts: 613

Rep: Reputation: 30
well I guess this could work:

Code:
use Fcntl qw(:DEFAULT :flock);

sysopen(FH, "somefile.txt", O_RDWR) or die "Can't open file: $!\n";
flock(FH, LOCKEX);

# read 5 lines
my $line;
$line = <FH> for 1..5;

# trucate the file at the current byte position
my $pos = tell(FH);
truncate(FH, $pos) or die "Unable to truncate: $!\n";

# close+unlock
close(FH);
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Truncate A File Dovetails Linux - Newbie 2 10-22-2005 06:58 PM
truncate lines with c alaios Programming 17 08-25-2005 08:51 AM
truncate the first character alaios Linux - General 1 02-10-2005 04:55 AM
Should I truncate an inode? akurtis Red Hat 0 08-02-2004 09:34 PM
truncate command butthead Linux - General 1 05-14-2002 03:40 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:29 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration