Sponsored Content
Top Forums Programming A C program required for portability Post 28593 by mbb on Friday 20th of September 2002 12:34:55 PM
Old 09-20-2002
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 ...
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Very Urgent help required in Shell Program

How do I Ftp, and rename multiple files in one unix script. I have to send it with .tmp extension , then rename it to .txt after FTP is done . I need to do a Mass rename of more than 1 file in a shell script , Urgent help required. (1 Reply)
Discussion started by: Suppandi
1 Replies

2. UNIX for Dummies Questions & Answers

Shell program:Help required on file formating

I have two files file1 and file2 as shown below: file1: name nameabc bcd nameabcdefg file2: age age1111 age2345 age6743 I have pasted one file on the other with the delimiter "|" and the resulttant file is: name|age nameabc|age1111 bcd|age2345 nameabcdefg|age6743 (6 Replies)
Discussion started by: udiptya
6 Replies

3. UNIX for Dummies Questions & Answers

Script portability

Hello, May I the right place if I need competencies to migrate DOS script into Unix platforme? Thanks in advance Thierry (9 Replies)
Discussion started by: tsconetti
9 Replies

4. Shell Programming and Scripting

portability issue linux(2.6) solaris10

the following simple scripts work fine on linux but fail on solaris: #!/bin/bash eval /usr/bin/time -f \'bt=\"%U + %S\"\' ./JUNK >> ./LOG 2>&1 cp ./LOG ./LOG_joe LC_joe=`cat ./LOG | wc -l` LC_joe=`echo $LC_joe-1|bc` tail -1 ./LOG > ./tmp head -$LC_joe ./LOG_joe > ./LOG rm ./LOG_joe ... (1 Reply)
Discussion started by: joepareti
1 Replies

5. Shell Programming and Scripting

Script Portability

Hi, I am writing a BASH shell script for a client. I am using BASH on a Macintosh Powerbook G4 running Leopard. My client will be using BASH on a PC running Ubuntu. My questions all revolve around making my script portable so that it will run on his machine. - Do I need to get any other... (2 Replies)
Discussion started by: msb65
2 Replies

6. UNIX for Dummies Questions & Answers

portability of int arrays from 32 to 64 bit systems

Dear All, I'm porting my scientific program from 32 to 64 bit system (use gcc, CentOS) and feel myself absolutely confused after reading general internet advices for that. Could you help me, please. The question is: can I use "old style" on 64 bit: -------- int * myIntArray; ... (3 Replies)
Discussion started by: German1234
3 Replies

7. Shell Programming and Scripting

simple program help required

The circumfrence of a circle is #!/usr/bin/perl print 2 * 3.141592654 * 12.50 \n"; # pi= 3.141592654 # r= 12.50 I need a simple program showing me all the steps..to modify the above to prompt for and accept a radius from the person running the... (3 Replies)
Discussion started by: Q2wert
3 Replies

8. Programming

Why is required to leave an empty line at the end of a C program?

I know it looks like a stupid question, but i really wanna know the reason. Actually, i think it's because the c compiler will detect it as the end of file "EOF" of the program, but, am i wrong? because it compiles it anyway, but keep showing warnings like "no new line at the end of file". I... (8 Replies)
Discussion started by: semash!
8 Replies

9. Shell Programming and Scripting

help required in program

I have below code, i need to modify it, to search for files (*.php,*.css,*.html) in those directores which have 777 permission, how to modify this code. Because it is moving all files. while true do sleep 60 DATE=$(date +%Y-%m-%d) # Creates dir only if it... (21 Replies)
Discussion started by: learnbash
21 Replies
REGEXP(2)							System Calls Manual							 REGEXP(2)

NAME
regcomp, regcomplit, regcompnl, regexec, regsub, rregexec, rregsub, regerror - regular expression SYNOPSIS
#include <u.h> #include <libc.h> #include <regexp.h> Reprog *regcomp(char *exp) Reprog *regcomplit(char *exp) Reprog *regcompnl(char *exp) int regexec(Reprog *prog, char *string, Resub *match, int msize) void regsub(char *source, char *dest, Resub *match, int msize) int rregexec(Reprog *prog, Rune *string, Resub *match, int msize) void rregsub(Rune *source, Rune *dest, Resub *match, int msize) void regerror(char *msg) DESCRIPTION
Regcomp compiles a regular expression and returns a pointer to the generated description. The space is allocated by malloc(2) and may be released by free. Regular expressions are exactly as in regexp(6). Regcomplit is like regcomp except that all characters are treated literally. Regcompnl is like regcomp except that the . metacharacter matches all characters, including newlines. Regexec matches a null-terminated string against the compiled regular expression in prog. If it matches, regexec returns 1 and fills in the array match with character pointers to the substrings of string that correspond to the parenthesized subexpressions of exp: match[i].sp points to the beginning and match[i].ep points just beyond the end of the ith substring. (Subexpression i begins at the ith left parenthe- sis, counting from 1.) Pointers in match[0] pick out the substring that corresponds to the whole regular expression. Unused elements of match are filled with zeros. Matches involving and are extended as far as possible. The number of array elements in match is given by msize. The structure of elements of match is: typedef struct { union { char *sp; Rune *rsp; }; union { char *ep; Rune *rep; }; } Resub; If match[0].sp is nonzero on entry, regexec starts matching at that point within string. If match[0].ep is nonzero on entry, the last character matched is the one preceding that point. Regsub places in dest a substitution instance of source in the context of the last regexec performed using match. Each instance of , where n is a digit, is replaced by the string delimited by match[n].sp and match[n].ep. Each instance of is replaced by the string delim- ited by match[0].sp and match[0].ep. Regerror, called whenever an error is detected in regcomp, regexec, or regsub, writes the string msg on the standard error file and exits. Regerror can be replaced to perform special error processing. Rregexec and rregsub are variants of regexec and regsub that use strings of Runes instead of strings of chars. With these routines, the rsp and rep fields of the match array elements should be used. SOURCE
/sys/src/libregexp SEE ALSO
grep(1) DIAGNOSTICS
Regcomp returns 0 for an illegal expression or other failure. Regexec returns 0 if string is not matched. BUGS
There is no way to specify or match a NUL character; NULs terminate patterns and strings. REGEXP(2)
All times are GMT -4. The time now is 03:28 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy