• Rob's side project: I recently started Gun-Forums.com and we currently have a $100 raffle - if you're into guns, join up and enter the raffle to win $100.00. Gun Forums

remove characters that are different from ABCD in a file

P

papori

Guest
Hi guys!
I have a text file, and I want to delete all the characters that are not A,B,C and D.
For example if my file contain this 2 lines:
ABCDEFGHIJ
GHKLABC

the new file will look like:
ABCD
ABC

I am looking for an easy way.. ideas?

Thanks,
Pap
 


C

cfajohnson

Guest

If you remove all characters other than A, B, C, and D, that will not
be the result; it will also remove the newline:
Code:
tr -dc 'ABCD' < "$file"
The result will be:
ABCDABC

What you want is:

Code:
tr -dc 'ABCD\n' < "$file"
 


Members online


Latest posts

Top