how to empty a file with DOS shell or Perl

Posted on 2009-07-04
Last Modified: 2012-05-07
In Unix, empty a file with
touch file.txt
> 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
Question by:jl66

Assisted Solution

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

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

Assisted Solution

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

Accepted Solution

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

Assisted Solution

Tintin earned 80 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.

LVL 69

Expert Comment

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

No error, no contents.

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
combine multiple lines 2 67
how to run this deletion request 4 30
Exclude all *.dat files from a 7z.exe command line 13 17
Perl Versus AWK? 7 52
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…

830 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