tailing a file which contains Control chracters


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers tailing a file which contains Control chracters
# 1  
Old 08-02-2011
tailing a file which contains Control chracters

Hi.
I have a log file which gets updated by a java process and it uses ASCII STX and ETX characters (i.e CTRL-B and CTRL-C characters) to demarcate each XML message logged.
so the format of the file is something like
Code:
 
STX XML_MESSAGE1
..
..
ETX STX XML_MESSAGE2
..
..
ETX

each XML message spans multiple lines as shown in ...

I dont have control over the process which writes these log files. I now need to write a utility which reads from one of these files and extract each XML message. While doing this i came up with this issue when using tail function.
so basically i did something like
Code:
tail -100f <file> > out_file &

and then after sometime compared the out_file to the original file. I noticed that some parts of some messages are missing. and they are replaced by ASCII NUL characters.
Looks like i only get this issue when the file is getting updated by new content. If i did
Code:
tail +0 <file> > out_file

, then i cant find any weird NUL characters and also the two files compare to be the same in content.
Looks like the issue is something to do with control characters - the STX and ETX. but then i am not in control of this file and i need some way of reading it and processing it. Initially i wrote a java program to do it and used Java IO API. but then when i got these NUL characters , i went and tried tail, which then gave me the same issue.
I am running the tail from a SunOS machine :
SunOS <host_name> 5.10 Generic_142901-08 i86pc i386 i86pc
and the file i am tailing is in a NAS storage and mounted using NFS.

Appreciate any help in trying to resolve this issue.
# 2  
Old 08-02-2011
tail ought not to modify the data passing through it. Could you show a sample of the data passed through hexdump -C to show the control characters?
# 3  
Old 08-02-2011
Thanks corona688 for your reply. yes, i know tail shouldn't modify the data going thru it. strange.
I dont have hexdump utility.
the characters are 2 and 3 in HEX
which maps to ASCII STX and ASCII ETX.
# 4  
Old 08-02-2011
how about od?
# 5  
Old 08-02-2011
od -A n -t x1 <file>
gave following:
02 XX XX XX XX
XX 03 02 XX XX
XX XX XX XX XX
03 02
etc.
XX are the data which are not 02 or 03 but valid ASCII characters.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Modification of perl script to split a large file into chunks of 5000 chracters

I have a perl script which splits a large file into chunks.The script is given below use strict; use warnings; open (FH, "<monolingual.txt") or die "Could not open source file. $!"; my $i = 0; while (1) { my $chunk; print "process part $i\n"; open(OUT, ">part$i.log") or die "Could... (4 Replies)
Discussion started by: gimley
4 Replies

2. UNIX for Beginners Questions & Answers

Extract string between two special chracters

Hi Folks - I'm trying to extract the string between two special characters, the "-" and "." symbols. The string format is as such: _PBCS_URL_PRD=https://plan-a503777.pbcs.us6.ocloud.com _PBCS_URL_TST=https://pln-test-a503777.pbcs.us6.ocloud.comIn the above case, I need to extract "a503777".... (7 Replies)
Discussion started by: SIMMS7400
7 Replies

3. Shell Programming and Scripting

Tailing logs from different files into one single file

Hi Please help me in finding a solution for tailing multiple log files and writing all of them into one common file. I have 4 log files with same name in 4 different folders. Whenever I post a Request - any one of these 4 log files gets updated with some log detail in the below format : ... (5 Replies)
Discussion started by: nisav
5 Replies

4. Shell Programming and Scripting

Better way to do tailing with awk

my current code: varA=$(tail -200 /var/log/data.txt | egrep -c "Capital|capitol") varB=$(tail -200 /var/log/data.txt | egrep -c "State|Country") varC=$(tail -200 /var/log/data.txt | egrep -c "City|Town") I want to do this a different way. something like: AllVars=$(echo $(tail -200... (5 Replies)
Discussion started by: SkySmart
5 Replies

5. Shell Programming and Scripting

Tailing last modified part of log file

I have a log file which contains data like this This log file is updated twice a day at 7am and 6pm, I want a script(which i will make run at 7:10am and 6:10pm) which should fetch only the last appended lines since last update.. I mean.. if i execute the script at 7.10am 3/3/2010 it... (4 Replies)
Discussion started by: user__user3110
4 Replies

6. Shell Programming and Scripting

Tailing new log file & echo the string on console

Guys, I do have a script that runs to take the server out from network, after running the script it is writing the new log file{outFile} in to directory . Now what i need is my script should tail the last modified file{outFile} & search the string {Server Status} ans should echo the same at the... (0 Replies)
Discussion started by: raghunsi
0 Replies

7. Shell Programming and Scripting

escape chracters

hi, how to echo \\ in unix ie echo the path \\dir1\dir2\\dir3 thanks, Sam (7 Replies)
Discussion started by: sam99
7 Replies

8. Shell Programming and Scripting

count the number chracters occurances in a line

Hi Could anybody tell me how to count the number of occurances of a character within a LINE. actually i have a single line with words seperated with '+' chracter e.g. abc+def+ghj+jkl+asd i want to separte the words above. Please provide the necessary logic in the form of a SHELL... (6 Replies)
Discussion started by: skyineyes
6 Replies

9. Shell Programming and Scripting

to see space, tab, end of the line chracters

what can I use ?? In vi, I can use :set list <-- and see end of line $.. or use cat -A but I am wondering if there is command or program that allows me to see all the hidden characters( space, tab and etc) Please help thanks. (3 Replies)
Discussion started by: convenientstore
3 Replies

10. UNIX for Dummies Questions & Answers

tailing logs

Hi I'd like to achieve the ff functionality; tail -f log | grep keyword ...... and then perform a function. That is, I like to tail a log and when a certain keyword appears I then want my script to play an audio file for example. Any ideas?? Cheers M (1 Reply)
Discussion started by: squeakywheel
1 Replies
Login or Register to Ask a Question