Hello,
I need to truncate a large file without deleting and touching it again.
i tried the below commands but no use because of the huge file size
cat <<! > errors
and
echo > errors
Could someone please help.
Thanks,
Sateesh (1 Reply)
I have one file which first line is blank and second line has some data.
$cat filename
output:
30-MAY-07
I want to store 30-MAY-07 value in one variable.
for that I wrote
var="`head -2 filename`"
It will give that result but I want to truncate the first line which is blank.
plz help. (2 Replies)
Hi All,
I have an application which writes log in to a file. The file size becomes around min of 800 MB a day. So I have written a script which backup the file and truncate the original file. My script is like this
cp X.log /backup/X.log1
> X.log
But the second truncate command... (3 Replies)
I am trying to concatenate 2 files, but before concatenation, I would like to strip off the final character from the first file.
The final character is a form feed (ascii 012 / hex 0C) and there will be an unknown number of these characters in the file. It is only the very last one which I want... (1 Reply)
Folder of e-mails in maildir format had been corrupted. Typical file name is 1246281161.6777.m21JH:2,S . The " :2,S prevents " copying to another device. How can I simply remove the last four characters? (2 Replies)
Hello all.
I would like to make a script (or two shell scripts) that will do the following.
I need the maximum file name and directory name to be 38 characters long.
As well, if shortening the file name ends up making all of the files in that directory have the same name, then I would like... (9 Replies)
Give shell script....which takes two file names as input and compares the contents, is both are same delete second file's contents.....
I try with "diff"...... but confusion how to use "diff" with if ---else
Thanking you (5 Replies)
Hi,
I am facing issue while reading data from a file in UNIX. my requirement is to compare two files and for the text pattern matching in the 1st file, replace the contents in second file by the contents of first file from start to the end and write the contents to thrid file.
i am able to... (2 Replies)
Hi one of the output of the command is as below
# sed -n "/CCM-ResourceHealthCheck:/,/---------/{/CCM-ResourceHealthCheck:/d;/---------/d;p;}" Automation.OutputZ$zoneCounter | sed 's/$/<br>/'
Resource List : <br>
*************************** 1. row ***************************<br>
... (2 Replies)
Discussion started by: vivek d r
2 Replies
LEARN ABOUT BSD
truncate
TRUNCATE(2) System Calls Manual TRUNCATE(2)NAME
truncate - truncate a file to a specified length
SYNOPSIS
truncate(path, length)
char *path;
off_t length;
ftruncate(fd, length)
int fd;
off_t length;
DESCRIPTION
Truncate causes the file named by path or referenced by fd to be truncated to at most length bytes in size. If the file previously was
larger than this size, the extra data is lost. With ftruncate, the file must be open for writing.
RETURN VALUES
A value of 0 is returned if the call succeeds. If the call fails a -1 is returned, and the global variable errno specifies the error.
ERRORS
Truncate succeeds unless:
[ENOTDIR] A component of the path prefix is not a directory.
[EINVAL] The pathname contains a character with the high-order bit set.
[ENAMETOOLONG] A component of a pathname exceeded 255 characters, or an entire path name exceeded 1023 characters.
[ENOENT] The named file does not exist.
[EACCES] Search permission is denied for a component of the path prefix.
[EACCES] The named file is not writable by the user.
[ELOOP] Too many symbolic links were encountered in translating the pathname.
[EISDIR] The named file is a directory.
[EROFS] The named file resides on a read-only file system.
[ETXTBSY] The file is a pure procedure (shared text) file that is being executed.
[EIO] An I/O error occurred updating the inode.
[EFAULT] Path points outside the process's allocated address space.
Ftruncate succeeds unless:
[EBADF] The fd is not a valid descriptor.
[EINVAL] The fd references a socket, not a file.
[EINVAL] The fd is not open for writing.
SEE ALSO open(2)BUGS
These calls should be generalized to allow ranges of bytes in a file to be discarded.
4.2 Berkeley Distribution March 29, 1986 TRUNCATE(2)