How to empty a file without removing it.


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to empty a file without removing it.
# 1  
Old 05-30-2007
How to empty a file without removing it.

I used to be able to do the following command on HP while largefile was being written to.

> echo " " > largefile

When I try the same on Solaris I get a message that the file already exists.

Is there a parameter that I need to setup in my env ?

Thanks in advance

Last edited by jxh461; 05-30-2007 at 10:12 PM..
# 2  
Old 05-30-2007
Jxh461,
There is an option in the "set" command that controls the truncation of files.
The following does not allow files to be truncated:
Code:
set -o noclobber

# 3  
Old 05-31-2007
Thanks for that info Shell. However, I am not sure if that is the cause of my problem. In any case how would I unset it if it were ?
# 4  
Old 05-31-2007
try this

>largefile
# 5  
Old 05-31-2007
Code:
echo '' >| largefile
# OR more simply
>| largefile

# 6  
Old 05-31-2007
cat /dev/null > largefile
# 7  
Old 05-31-2007
set +o noclobber. Smilie


Then any of the above commands will work.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk :quick question removing empty line.

How to write in awk to remove lines starting with "#" and then process the file: This is not working: cat file|awk '{if ($0 ~ /^#/) $0="";print NF>0}' When I just give cat file|awk '{if ($0 ~ /^#/) $0="";print }' it prints the blank lines . I don't wnat the blank lines along with the... (15 Replies)
Discussion started by: rveri
15 Replies

2. UNIX for Dummies Questions & Answers

Removing empty lines at the end of a Tab-delimited file

I'm trying to remove all of the empty lines at the end of a Tab delimited file. They have no data just tabs. I've tried may things, here are a couple: sed /^\t.\t/d File1 > File2 sed /^\t{44}/d File1 > File2 What am I missing? (9 Replies)
Discussion started by: SirHenry1
9 Replies

3. UNIX for Dummies Questions & Answers

Removing empty folders

Hello, I have a folder that contains all my music. Recently, I started using a different media player, and I let it manage my music folder. It has sorted all my music neatly in folders by artist and album. However, all the old folders that the songs used to be in are still there, yet they are... (2 Replies)
Discussion started by: emveedee
2 Replies

4. Ubuntu

dpkg: warning: while removing directory not empty

Hi, I am getting this warning messages when I run dpkg --purge dpkg -r apt-get remove --purge aptitude purge with sudo permission to remove completely a custom application that is installed through debian dpkg command. Some of the directories in that package install path is still left out... (0 Replies)
Discussion started by: royalibrahim
0 Replies

5. Shell Programming and Scripting

Removing empty lines(space) between two lines containing strings

Hi, Please provide shell script to Remove empty lines(space) between two lines containing strings in a file. Input File : A1/EXT "BAP_BSC6/07B/00" 844 090602 1605 RXOCF-465 PDTR11 1 SITE ON BATTERY A2/EXT... (3 Replies)
Discussion started by: sudhakaryadav
3 Replies

6. UNIX for Dummies Questions & Answers

Getting same exit status for empty and non empty file

Hi All, I am checking for a empty input file to do some further action , but I am getting exit status 0 in both the cases , for empty and non empty file both. The value of $? is coming 0 in if part also and else part too. #!/bin/ksh if ]; then echo "data" # exit 0 echo "$?" else... (4 Replies)
Discussion started by: mavesum
4 Replies

7. Shell Programming and Scripting

removing empty tags

Hi, I have a file as shown below. <crown:clinicalData> <crown:alb date="2008-07-10" lowValue="3.50" method="BCG" value="3.50"/> <crown:cre date="2008-07-10" value="9.5"></crown:cre> <crown:ktvHdAd> </crown:ktvHdAd> <crown:ktvPdAd> </crown:ktvPdAd> ... (1 Reply)
Discussion started by: vijayhai
1 Replies

8. UNIX for Dummies Questions & Answers

Removing empty folders using 'find'

Hey there! I try to use 'find' to remove empty directories like this: find . -depth -type d -empty -exec rm -rf {} ';' It works just fine, but there are some directories i want to exclude. So i tried to do sth like this: find . -depth -type d -empty -exec grep -v "not this one please" -exec... (5 Replies)
Discussion started by: deTTo
5 Replies

9. UNIX for Dummies Questions & Answers

Removing empty folders using the "find" command

Hi I'm trying to remove empty sub-folders from 1 main folder using the find method, but the "- empty" parameter isn't recognized by my Unix version. Any idea how to implement such thing? Thanks. (3 Replies)
Discussion started by: biot
3 Replies

10. Programming

Removing empty spaces and adding commas

I have a file which contains numbers as follows: 1234 9876 6789 5677 3452 9087 4562 1367 2678 7891 I need to remove the empty spaces and add commas between the numbers like: 1234,9876,6789,5677,3452, 9087,4562,1367,2678,7891 Can anyone tell me the command to do... (4 Replies)
Discussion started by: jazz
4 Replies
Login or Register to Ask a Question