473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

An Odd Delimeter

For some strange reason my file is split by the  character. I didn't choose the character, and it is, at the moment, unlikely to change. In Unix the character appears as ^[ inside a file, but any time I run attempt to run a command on the line to split the character, it deletes the character after the ^[ and fails to even find a ^[.

Line appears as follows. With the ^[ representing the character above.

123456^[SomeString^[AnotherString^[0.00000 sec

I am attempting to get the time before the sec, but so far my commands have failed because character tends to delete the first number before the .
My string ends up

123456omeStringnotherString.00000 sec

The Strings may contain * characters, Spaces, and Underscores making it difficult to split.

and I can not retrieve the correct number of seconds.
Standard Unix awk, grep, and other commands have been attempted.
Attempts to use Perl's Regular expression on just the ^ return no results
Expand|Select|Wrap|Line Numbers
  1. @cutline = split(/\^/, $line, 5);
  2.  
splitting on \[ also produces no results.

If Anyone can offer some help, it would be appreciated.
Edit:::
(I've noticed the Character doesn't appear at all in the forum either...how fun. It looks a bit like this <- )
Feb 5 '08 #1
6 1342
KevinADC
4,059 Expert 2GB
post some of the lines from the file or better attach some of them to a post.
Feb 5 '08 #2
As requested here are a couple lines of the file as seen in WordPad

000000*XXX_XXXXX_XXXX0.305687 sec
000003xxx*XXXX_XXXX_XXXX_XXXX0.046740 sec

As seen in vi
000000^[*^[XXX_XXXXX_XXXX^[0.305687 sec
000003^[xxx*^[XXXX_XXXX_XXXX_XXXX^[0.046740

Replace the x's with whatever you'd like, it can be any length and include spaces. the X's have varying lengths as well. I'm trying to retrieve the time in seconds which can range from less then 1 second to more then 10 so I can't know exactly how many numbers to retrive prior to the space.

Once again, the delimter that is used, (which shows in WordPad) will probably not be seen. It is a Left pointing arrow, and I havn't been able to find an ASCII value of it yet.
Feb 5 '08 #3
eWish
971 Expert 512MB
Since I can not see the actual delimiter here is an example using [ as the delimiter. The regex I am using is greedy which can be fine tuned for your needs. Essentially what the regex does is looks for the last delimiter, then gets the data following it provided it starting with the numeric character until the end of the string.

Expand|Select|Wrap|Line Numbers
  1. my @sec_array;
  2. my @data = ('000000^[some string here^[000.00 sec', 
  3.             '000000^[some string here^[111.11 sec', 
  4.             '000000^[some string here^[222.22 sec',  
  5.             '000000^[some string here^[333.33 sec');
  6.  
  7.     for(@data) {
  8.         push @sec_array, $_ =~ /\[(\d+.*)$/g;
  9.     }
  10.  
  11. print join("\n", @sec_array);
Prints
000.00 sec
111.11 sec
222.22 sec
333.33 sec

--Kevin
Feb 6 '08 #4
I have been able to get the sequence after a delimiter in the past. The problem in this case is that I can not find a matching expression for the delimiter, since that doesn't seem possible at the moment (if I can't get the blasted thing to show); Is there was a way to retrieve the time going backwards? What I would like then is, from the final space before 'sec', to retrieve X many digits a '.' then 1 or 2 more digits going in reverse. Or if that isn't feasible, find the first digit then step back and pick up the double until the space. I've been looking through my books and online for the subject, but keep coming up short. I appreciate the help.
Feb 6 '08 #5
eWish
971 Expert 512MB
Using the code I posted above you can set the \d (digits) to a minimum and maximum number if you wish.

Expand|Select|Wrap|Line Numbers
  1. excerpt from perlre
  2. {n}    Match exactly n times
  3. {n,}   Match at least n times
  4. {n,m}  Match at least n but not more than m times
As an example if you changed the regex above to this then, you can tell it the minimum and maximum numeric characters to allow.

Expand|Select|Wrap|Line Numbers
  1. push @sec_array, $_ =~ /\[(\d{1,3}\.\d{2}).*$/g;
--Kevin
Feb 6 '08 #6
Thanks for the help. I've found that the delimiter is detected if I just have it detect everything other then a character or digit. Your code came in handy. Thanks again.
Feb 6 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

21
by: tomasio | last post by:
Dear Group, The Site under the following link (http://tomasio.laudatio.com/temp/schiepek/index.html) displays as I want it to in IE 6 (under Win XP) but does not render correctly in Firefox...
8
by: Thomas van den Berg | last post by:
how can I count the number of blank-seperated word groups in a single field. The format I receive is aaa (aaa aaa )n(nnn). aaa can be any number of words, any length. The n(nnn) is not fixed length...
2
by: Ron | last post by:
I am trying to read a delimited textfile to the console window as follows: using System.IO; StreamReader oRead; string str1; object str2; oRead = new StreamReader(strPath +...
4
by: sushi | last post by:
Hello, I want to make an http post request to a site. I want to pass a paramaeter having xml such as report=<abc>abc</abc> to it. When I try to do this, is gives exception. And If send...
10
by: Claud Balls | last post by:
I am splitting large files based on a text delimeter, but I don't want the delimeter left out of the string. For example if I had a string "NAME: Bill TOWN: Helena NAME: Frank TOWN: Helena" I...
1
by: Voronkov Konstantin | last post by:
Hello all! std::ostringstream stream; stream << 8080; std::string str = stream.str(); // str == "8 080" The code shown above in mine big program result the str variable value to
6
by: tbh | last post by:
hi, i love generic collections. one thing I very frequently want to be able to do is take say a List<T> and join it into a string with a certain delimiter. (in each case the underlying T...
2
by: Mr Shore | last post by:
http://www.devpro.it/javascript_id_126.html has any one any idea about this applet? code as below: /** * SourceMap class, * reads a generic language source code and returns its map. *...
3
by: manjuks | last post by:
Hi, I have some different types of data like Employee number Employee Name Employee sex . . .
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.