![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | 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!!! |
|
||||
|
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;
}
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|