The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Special Forums > UNIX Desktop for Dummies Questions & Answers
Google UNIX.COM



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #5 (permalink)  
Old 10-04-2007
porter porter is offline
Registered User
 

Join Date: Jan 2007
Posts: 2,965
As I'm not into awk, here is something else...

Code:
#include <stdio.h>
#include <string.h>

static int is_junk(c)
int c;
{
	if ((c >= '0')&&(c <='9')) return 0;
	return 1;
}

int main()
{
char buf[4096];

	while (fgets(buf,sizeof(buf),stdin))
	{
		int i=strlen(buf);
		while (i--)
		{
			if ((buf[i]=='\n')||is_junk(buf[i]))
			{
				buf[i]=0;
			}
			else
			{
				break;
			}
		}
		printf("%s\n",buf);
	}

	return 0;
}
Reply With Quote