Results 1 to 8 of 8
how to remove undesired characters(ascii) only first column in huge the file? would you please tell what is wrong my testing command.
EXAMPLE FILE
201208|123456|US|CA
§201208|23457|US|CA
o201208|258741|US|TX
Â201208|123458|US|TX
¢201208|2851452|CA|TN
EXPECT ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 10-29-2012 #1Just Joined!
- Join Date
- Oct 2012
- Posts
- 22
how to remove undesired characters(ascii) first column in the file
how to remove undesired characters(ascii) only first column in huge the file? would you please tell what is wrong my testing command.
EXAMPLE FILE
201208|123456|US|CA
§201208|23457|US|CA
o201208|258741|US|TX
Â201208|123458|US|TX
¢201208|2851452|CA|TN
EXPECT FILE OUTPUT
201208|123456|US|CA
201208|23457|US|CA
201208|258741|US|TX
201208|123458|US|TX
201208|2851452|CA|TN
I did as follows. does not work;
tr -cd '\11\12\40-\176' < testfile.txt> resultfile.txt
or
perl -ane '{ if(m/[[:^ascii:]]/) { print } }'>resultfile.txt
- 10-29-2012 #2Linux User
- Join Date
- Jan 2007
- Location
- cleveland
- Posts
- 468
welcome to the forum
don't know what those weird characters are, but using "od -c" to find their octal codes, and using 'tr" as you did--this seems to
work on your sample
tr -d "\302\247\303\202\302\242\o" <example_filethe sun is new every day (heraclitus)
- 10-29-2012 #3Trusted Penguin
- Join Date
- May 2011
- Posts
- 3,680
Hello and welcome!
As well as perl and tr, you could use sed, too, e.g.:
that sed expression says "any line in which the first character is NOT a digit will have that character deleted". not elegant, but does the job.Code:cat input.txt|sed -e 's|^[^0-9]||' > output.txt
- 10-29-2012 #4Just Joined!
- Join Date
- Oct 2012
- Posts
- 22
- 10-29-2012 #5Trusted Penguin
- Join Date
- May 2011
- Posts
- 3,680
- 10-30-2012 #6Just Joined!
- Join Date
- Oct 2012
- Posts
- 22
thank you!
- 10-30-2012 #7Just Joined!
- Join Date
- Oct 2012
- Posts
- 22
Thank you for your answer.
- 10-30-2012 #8
Did that work? I think awk would have been easier..... never mind I saw the post wrong.


Reply With Quote

