Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Any programmer here can help me?

Status
Not open for further replies.

ahmad_abdulghany

Advanced Member level 4
Advanced Member level 4
Joined
Apr 12, 2005
Messages
1,206
Helped
102
Reputation
206
Reaction score
22
Trophy points
1,318
Location
San Jose, California, USA
Activity points
11,769
I have a file that contains plain text.

In some lines (a lot of them), there're numbers having the format: AA:BB:CC,DDD (e.g. 01:32:53,453).

I want to run any script on that text file such that all numbers in the format above are been converted to: AA:BB:CC+6,DDD (i.e. the CC number increased by 6).

Can anybody show me how to do it? I'm not a prefect programmer, and I want it little urgently.

If it could be done using Matlab, that will be nice, however, other options are all appreciated. :)

Thanks a lot in advance,
Ahmad,
 

Asslamo 3likom

The following is in C , matlab is some thing like this

USe fopen to open the file
and create another file
then while !EOF to make sure that you have not reached the end of file
with in the wile
use fgetc to read character by character and monitor the ":"
count them and when you count 2 of them you are at your target read the next 2 char and procces them and write the result back to the new file
for all other characters write them as they are in the new file

at the end of file close both files by fclose

Note I assume that the : char only appears in your target pattern.
You must use a c Reference or matlab for checking syntax
this just an overview

Salam
Hossam Alzomor
www(.)i-g(.)org
 
Asslamo Alaikom !
im not a good programmer but i think ...in c
make two large char arrays,,aray1[],aray2[].leave aray1[] empty and fill aray2[] with string contained in ur file.then
in the loop
for(index=0;index<length;index++)
{
aray1[index]=aray2[index]
if(aray2[index]=='C')
{
aray1[index+1]='C'
aray1[index+2]='+'
aray1[index+3]='6'
index++;
}
}
:| dats wat i understood.if all this is waste then sorry 4 wasting ur time in reading it:!:
Allah Hafiz
 

Hey you :)
I don't want to complicate it!!
I can do it in single line with Perl like that:

Code:
s/(\d\d),(\d\d\d)$/$1+6$2/ge

This is a single line regular expression, if i ran it on the whole file, it will do it, but the problem is, Perl (as far as i know) can't understand unicode text, and the text file i want to process contains Arabic text (unicode)..

This is my problem..
Now, can you help me?

Thanks and regards,
Ahmad
 

ahmad_abdulghany said:
Hey you :)
I don't want to complicate it!!
I can do it in single line with Perl like that:

Code:
s/(\d\d),(\d\d\d)$/$1+6$2/ge

This is a single line regular expression, if i ran it on the whole file, it will do it, but the problem is, Perl (as far as i know) can't understand unicode text, and the text file i want to process contains Arabic text (unicode)..

This is my problem..
Now, can you help me?

Thanks and regards,
Ahmad

You can use a variable
$tmp=$1+6;

the script is like this:

************
!#/usr/bin/perl -w

while(<>)
{
/(\d\d),(\d\d\d)$/;
$tmp=$1+6;
s/(\d\d),(\d\d\d)$/$tmp,$2/;
print;
}
************
 
Thank you RDRyan,
But my single line code include all what you put in yours :)

as the option 'g' at the end of RE means global search and replace then, no need for the while loop, and the option 'e' will evaluate mathematical operations in the RE, then no need for the $temp variable..

But I only missed a 'comma' i.e. the code should be like that:

s/(\d\d),(\d\d\d)$/$1+6,$2/ge

Regards,
Ahmad,
 

yes perl is the best choice to do it!
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top