Visit Our UNIX and Linux User Community


Binary line being inserted while truncating a file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Binary line being inserted while truncating a file
# 1  
Old 09-15-2009
Binary line being inserted while truncating a file

Hi All,

I have a ln between two files (say ln a b), when i truncate file " b ", this truncates file " a " also, a binary line is being added as the first line of both the files.

This is causing problems with other scripts which grep on the above files.

(though i can work my way around by using grep -a)

Can anyone comment why the binary line is being added.

Thanks in anticipation

Akshay
# 2  
Old 09-15-2009
So, how are you truncating the file(s) - what command?
# 3  
Old 09-15-2009
You've got to give us some more information on how you truncate the file, what kind of link you use, and what and how another application might write into that file, because I can't yet reproduce that behaviour:
Code:
bash-3.2$ perl -e 'for($i=0;$i<100;$i++){print chr(ord('A')+$i%26)x40,"\n";}' > test1.txt
bash-3.2$ ln -s test1.txt test2.txt
bash-3.2$ ln test1.txt test3.txt
bash-3.2$ ll test*.txt
-rw-r--r-- 2 pludi users 4100 15. Sep 08:53 test1.txt
lrwxrwxrwx 1 pludi users    9 15. Sep 08:53 test2.txt -> test1.txt
-rw-r--r-- 2 pludi users 4100 15. Sep 08:53 test3.txt
bash-3.2$ head test1.txt
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG
HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
bash-3.2$ head test2.txt
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG
HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
bash-3.2$ head test3.txt
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG
HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
bash-3.2$ : > test1.txt
bash-3.2$ head test1.txt
bash-3.2$ head test2.txt
bash-3.2$ head test3.txt
bash-3.2$ ll test*.txt
-rw-r--r-- 2 pludi users 0 15. Sep 08:54 test1.txt
lrwxrwxrwx 1 pludi users 9 15. Sep 08:53 test2.txt -> test1.txt
-rw-r--r-- 2 pludi users 0 15. Sep 08:54 test3.txt

# 4  
Old 09-15-2009
Quote:
Originally Posted by pludi
You've got to give us some more information on how you truncate the file, what kind of link you use, and what and how another application might write into that file, because I can't yet reproduce that behaviour
Hi,

Following are the steps which we follow :-
1) a log file is generated through the redirection of Jboss' run.sh
Code:
nohup $JBOSS_HOME/bin/run.sh -c Instance_Name >  abc.log &

2)the above log file abc.log is then linked via :-
Code:
ln abc.log $JBOSS_HOME/server/deploy/jboss-web/ROOT/abc.txt

3) Every night a copy of the log file in ROOT is made and the original one is truncated :-
Code:
>abc.txt

After step 3, a new binary line is found as the first line of the truncated file

So a few points :-
1) the log file is being written by JBoss
2) linking is not via "-s"

Hope i cleared some doubts
# 5  
Old 12-17-2009
hi all,

sorry for replaying on this thread again.

but i came across this problem again,

to summarize , binary line of "^@" gets inserted into a file whenever i try to truncate it by > /filename. This has happened to files which had no other script/service writing to it.

though i tried to truncate the files by echo /dev/null > /filename, and am keeping my fingers crossed this time.

any insight into this rouge behaviour will be appreciated.

thanks in anticipation

cheers
 

Previous Thread | Next Thread
Test Your Knowledge in Computers #435
Difficulty: Medium
Angular and AngularJS are web application frameworks to use for developing multi-page web applications.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to add new line after every data inserted to file?

Hi all, I need help for solve my problem. my problem is like this.. i want to add many word to file. but after I add 1 word, the second word should be in the under of the first word. i have tried but the result is like this word1word2word3 i want the result to be like this word1 word2... (5 Replies)
Discussion started by: weslyarfan
5 Replies

2. Shell Programming and Scripting

Convert binary file to csv and then back to the binary format

Hello *nix specialists, Im working for a non profit organisation in Germany to transport DSL over WLAN to people in areas without no DSL. We are using Linksys WRT 54 router with DD-WRT firmware There are at the moment over 180 router running but we have to change some settings next time. So my... (7 Replies)
Discussion started by: digidax
7 Replies

3. Shell Programming and Scripting

Truncating a mail file

Hi, I have a Unix mail file that I need to truncate, based on the date of the messages. For those not familiar with the format, it is a single file for each user, with the first line of the mail message looking like the following: From user@sitename.com Thu Apr 21 05:40:33 2011 Each... (3 Replies)
Discussion started by: joed
3 Replies

4. Shell Programming and Scripting

How to avoid the truncating of multiple spaces into a single space while reading a line from a file?

consider the small piece of code while read line do echo $line done < example content of example file sadasdasdasdsa erwerewrwr ergdgdfgf rgerg erwererwr the output is like sadasdasdasdsa erwerewrwr ergdgdfgf rgerg erwererwr the... (4 Replies)
Discussion started by: Kesavan
4 Replies

5. Shell Programming and Scripting

script to detect a file from inserted usb and puts into a Variable

There is a same named log file that I have on my 2 different android phones. When I plug it into my computer, it appears in the media folder, For example the first android phone: /media/F6BA-0AF5/folder/A.log I want to put that into a variable to be manipulated.... (3 Replies)
Discussion started by: tobenguyen
3 Replies

6. Shell Programming and Scripting

sed truncating last line if EOF is not with newline

sed 's|^xyz.abc *= *.*|xyz.abc=60|' /test/myFile.properties > /test/myFile.properties1 myFile.properties has the last line as xyz.abc=23 does not end with newline. When I run this command the last line is truncated if there is no newline character at EOF. Looking for an alternative here. (1 Reply)
Discussion started by: sunn_hps
1 Replies

7. UNIX for Dummies Questions & Answers

Truncating file based on date

Hi, I need to truncate a file based on date.Suppose i have a log file which is getting updated every date,i need to keep 7 days worth of data(like sysdate-7) and rest i want to truncate it.Can some help me? (5 Replies)
Discussion started by: Param0073
5 Replies

8. Shell Programming and Scripting

Removing inserted newlines from a fileld of fixed width file.

Hi champs! I have a fixed width file in which the records appear like this 11111 <fixed spaces such as 6> description for 11111 <fixed spaces such as 6> some more field to the record of 11111 22222 <fixed spaces such as 6> description for 22222 <fixed spaces such as 6> some more field to the... (8 Replies)
Discussion started by: enigma_1
8 Replies

9. Shell Programming and Scripting

Truncating FILE data BASED ON A PATTERN

HI I HAVE A PROBLEM,MY SOURCE FILE IS OF PATTERN S1,E-Certified,29,29,2.7,Certified,4,3,2.7,,0,0,0 S2,Certified,4,3,2.7,,0,0,0,,0 S3,E-Certified,29,29,2.7,,0,0,0 S4,,0,0,0,,0,0,0,,0,0,0,,0,0,0 AND THE EXPECTED OUTPUT IS S1,E-Certified,29,29,2.7 S1,Certified,4,3,2.7... (1 Reply)
Discussion started by: pkumar3
1 Replies

10. Shell Programming and Scripting

truncating leading zeros of a column in a file

Hi I have a file in which I have 5 columns which are delimited by | as shown ABC|12|YAK|METRIC|000000019.5 XYZ|10|ABX|META|000000002.5 Now my requirement is to take the last column trim the leading zero's for that column values and write back to the same file in the same... (7 Replies)
Discussion started by: nvuradi
7 Replies

Featured Tech Videos