Unix/Linux Go Back    

Programming Post questions about C, C++, Java, SQL, and other programming languages here.

A C program required for portability


regex, regular expressions

Thread Tools Search this Thread Display Modes
Old Unix and Linux 09-20-2002   -   Original Discussion by nmsinghe
nmsinghe nmsinghe is offline
Registered User
Join Date: Sep 2002
Last Activity: 28 September 2002, 6:53 PM EDT
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Unix or Linux Question A C program required for portability

I have to solve a problem for my wife who is engaged in Research in Breast Cancer.

1. She has frequently to search a long single line of alphabetic characters (lower case) for an exact match of a string.

e.g. mwaaagglwrsraglralfrsrdaalfpgcerglhcsavscknwlkkfasktkkkvwyespslgshstykpskleflmrstskktrkedharlralngll ykaltdllctpevsqelydlnvelskvsltpdfsacraywkttlsaeqnahmeavlqrsaahmslisywqsqtldpgmkettlykmisgtlmphnpaapq srpqapvcvgsimrrstsrlwstkggkikgsgawcgrgrwls

2. The ONLY two strings to be searched for are -


The - can be any of the following characters


3. Once an exact match/s has been made it is essential to know the number of characters from the start of the line inclusive of the 6 character string to each match.

Can anyone suggest a program in ANSI C that will compile in the first instance in Solaris (SunOS 5.9).

But is portable (source and then re compile) to HP-UX and AIX and to XP.

It is urgent.



p.s. The immediate need has been solved with a ksh script but c is necessary to match some other utilities.

Also we have to solve a problem in that the raw data although shown as one line above; comes as many lines sometimes as many as 50 so we have to join these lines to make one single line. It does not alter the data at all as it is shown as many lines only on for ease of display purposes.

Last edited by nmsinghe; 09-20-2002 at 12:20 PM..
Sponsored Links
Old Unix and Linux 09-20-2002   -   Original Discussion by nmsinghe
mbb mbb is offline
Registered User
Join Date: Aug 2001
Last Activity: 25 October 2010, 3:31 AM EDT
Location: UK
Posts: 104
Thanks: 0
Thanked 0 Times in 0 Posts
Ok. To answer the second part first. To strip out carriage returns from your input file do:

awk '{printf("%s"), $0}' filename > newfile

The awk command should be standard across most Unix O/S.

In HP-UX use the functions: regcomp, regexec. These functions allow you to process regular expressions. In other words you may search a string for a pattern (like the ones you have described).

Sorry I don't have time to explain these functions in depth or write you a little test program, but regexec will point you to where it finds the first match in your line (in a pointer). If you called the function again it will return a pointer to the next pattern in your string. To work out the number of characters between each expression found you would subtract the first pointer value from the second pointer value and so on ...

I do know that you may have portability issues with the regexec and regcomp functions. When my trainee wrote a program and ported it to windows he found that a different library with different function names was required. To make matters worse the windows functions had different rules for regular expressions.
I would not be surprised if you encountered similiar issues between different flavours of Unix.

If portability is an issue you may have to write your own parsing algorithms ...

Sorry I can't be more help but I have run out of time ...
Sponsored Links

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
help required in program learnbash Shell Programming and Scripting 21 11-07-2011 04:14 PM
Why is required to leave an empty line at the end of a C program? semash! Programming 8 05-28-2010 06:48 PM
simple program help required Q2wert Shell Programming and Scripting 3 12-26-2009 04:22 PM
Shell program:Help required on file formating udiptya UNIX for Dummies Questions & Answers 6 02-04-2008 05:10 AM
Very Urgent help required in Shell Program Suppandi Shell Programming and Scripting 1 12-09-2005 08:33 AM

All times are GMT -4. The time now is 05:41 PM.