C Program Data Conversion

Jean-Pierre Radley jpr at murphy.com
Wed Sep 19 11:35:36 AEST 1990


In article <681 at csoftec.csf.com> cmanis at csoftec.csf.com (Cliff Manis) writes:
>                I need help in writing a 'C' program
>I need help in writing a 'C' program to do the following.  It must be simple
>but I can't seem to get it working.  Below is a datafile which in which 
>line 1 always starts with "1990" and it ends with a carriage return, and
>goes to line two of that data record.  The data separators are spaces.
>All I want to do is:  If the line start with "1990", move to the end, delete
>the carriage return, put in a space, and append the second line.
>
>/below is a sample of datafile/
>1990 aaa bbbbb ccc ddd eeeeeee fff
>ggggg
>1990 aaa bbb ccccccccc ddd eee fff
>gggggggggg
>1990 aaa bbb ccc ddddddd eee fff
>ggggggg

>There must be a million ways to do this, but I only need one ! !

A C-program sounds like overkill. Why not use 'awk'?

awk datafile '
/^1990/	{ FIRSTPART = $0 ; next }
	{ printf "%s %s\n", $FIRSTPART, $0 }
' > newdatafile

BTW, why is this question in a newsgroup with 'sco' in its name? Sounds like a
pretty general Unix question.
-- 
Jean-Pierre Radley		jpr at jpradley		CIS:72160,131



More information about the Comp.unix.xenix.sco mailing list