Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

how to empty a file with DOS shell or Perl

Posted on 2009-07-04
5
Medium Priority
?
333 Views
Last Modified: 2012-05-07
In Unix, empty a file with
touch file.txt
or
> file.txt
In DOS or Perl, is anything similar I can use? For example,
07/04/2009  06:20 PM             2,945 file.txt
Want it to be
07/04/2009  06:22 PM             0 file.txt
0
Comment
Question by:jl66
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 9

Assisted Solution

by:ghostdog74
ghostdog74 earned 120 total points
ID: 24778910
perldoc -f truncate.

please read the Perl documentation, perldoc perlopentut (as well as others) for more info.
0
 
LVL 84

Assisted Solution

by:ozo
ozo earned 760 total points
ID: 24778922
perl -e1 > file.txt
0
 
LVL 10

Accepted Solution

by:
jfromanski earned 800 total points
ID: 24778983
in DOS
ECHO ON > file.txt
0
 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 320 total points
ID: 24778984
touch file.txt

does not empty a file.

By DOS, I'm assuming you mean Windows command shell.  You can do

TYPE >file.txt

it will give you an error, but it will empty the file.

0
 
LVL 71

Expert Comment

by:Qlemo
ID: 24779190
The traditional DOS way is
copy nul file.txt

No error, no contents.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question