![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX Desktop for Dummies Questions & Answers Questions regarding GNOME, KDE, CDE, Open Office, etc go here. All UNIX and Linux Newbies Welcome !! |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
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!!! |
| Forum Sponsor | ||
|
|
|
|||
|
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? |
|
|||
|
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! |
|
|||
|
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;
}
|
| Thread Tools | |
| Display Modes | |
|
|