The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Special Forums > UNIX Desktop for Dummies Questions & Answers
.
google unix.com



UNIX Desktop for Dummies Questions & Answers Discuss UNIX and Linux user interfaces like GNOME, KDE, CDE, and Open Office 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 02:08 PM
Deleting end of line $ character in file bwrynz1 UNIX for Advanced & Expert Users 3 01-08-2008 01:17 PM
Deleting all content in a file from command line kingdbag UNIX for Dummies Questions & Answers 2 07-20-2006 07:00 PM
Deleting the blank line in a file and counting the characters.... rkumar28 Shell Programming and Scripting 4 04-17-2005 12:13 PM
Deleting end line spaces for along file osymad Shell Programming and Scripting 3 02-23-2005 01:56 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-04-2007
dave_nithis dave_nithis is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 17
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!!!
  #2 (permalink)  
Old 10-04-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
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?
  #3 (permalink)  
Old 10-04-2007
dave_nithis dave_nithis is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 17
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!
  #4 (permalink)  
Old 10-04-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
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?
  #5 (permalink)  
Old 10-04-2007
porter porter is offline Forum Advisor  
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;
}
  #6 (permalink)  
Old 10-05-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,509
try this
Code:
awk 'BEGIN{OFS=FS=","}{$NF=$NF+0}1' file
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:44 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0