The UNIX and Linux Forums  

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


UNIX Desktop for Dummies Questions & Answers Questions regarding GNOME, KDE, CDE, Open Office, etc go here. All UNIX and Linux Newbies Welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
deleting a line but keeping the same file laiko UNIX for Dummies Questions & Answers 2 05-13-2008 11:08 AM
Deleting end of line $ character in file bwrynz1 UNIX for Advanced & Expert Users 3 01-08-2008 09:17 AM
Deleting all content in a file from command line kingdbag UNIX for Dummies Questions & Answers 2 07-20-2006 04:00 PM
Deleting the blank line in a file and counting the characters.... rkumar28 Shell Programming and Scripting 4 04-17-2005 09:13 AM
Deleting end line spaces for along file osymad Shell Programming and Scripting 3 02-23-2005 09:56 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-03-2007
Registered User
 

Join Date: Sep 2007
Posts: 16
Stumble this Post!
Exclamation Deleting Junks at the end of each line in a file

Is there any way to delete the Junk Characters(Invalid Characters like ^,',",),(,&,# etc.,) at the end of each record in a file?

I want to do this using a single line script.

Thanks to all in advance!!!
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 10-04-2007
Registered User
 

Join Date: Jan 2007
Posts: 2,965
Stumble this Post!
Define "junk"

Define "record"

Define "single line script", is back-slash allowed? What about the interpretor indicator in the first line? Does it have to fit in 131, 79 or 65 characters?

Are there any other nefarious restrictions, like can't use sed or awk?
Reply With Quote
  #3 (permalink)  
Old 10-04-2007
Registered User
 

Join Date: Sep 2007
Posts: 16
Stumble this Post!
Single line Script - You can use any commands but i dont want for loop,if loop,while loop etc.,I want a simple script.

Record - Am calling Each line in a file as record

Junk - As I said unwanted characters including backslash

Ex:
"401","1G1AL55F377159935 ",30482,"MD","3","09/17/2007",9000 -Valid record
"401","1G1AL55F377159935 ",30482,"MD","3","09/17/2007",9000[ - invalid
"401","1G1AL55F377159935 ",30482,"MD","3","09/17/2007",9000; - invalid
"401","1G1ZT58N47F140841 ",29098,"MD","3","09/17/2007",10600'" - invalid
"401","1G1ZT68N57F138781 ",27403,"GA","1","09/17/2007",10100' - invalid
"401","1G4HD57227U217222 ",7163,"MI","3","09/17/2007",21600: - invalid

You can certainly use awk or sed!!
Thanks!
Reply With Quote
  #4 (permalink)  
Old 10-04-2007
Registered User
 

Join Date: Jan 2007
Posts: 2,965
Stumble this Post!
Quote:
Originally Posted by dave_nithis View Post
Junk - As I said unwanted characters including backslash
We don't know what you don't want, do you mean all non numeric characters?

Is it always a single character at the end?
Reply With Quote
  #5 (permalink)  
Old 10-04-2007
Registered User
 

Join Date: Jan 2007
Posts: 2,965
Stumble this Post!
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
  #6 (permalink)  
Old 10-04-2007
Registered User
 

Join Date: Sep 2006
Posts: 1,542
Stumble this Post!
try this
Code:
awk 'BEGIN{OFS=FS=","}{$NF=$NF+0}1' file
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 05:12 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0