0

I have a list that has for some reason got some non alphanumeric characters appended to the end.

I would have thought it would be a simple case of running :

sed 's/[^A-Za-z0-9]$//'

To replace these trailing characters. Unfortunatley the above seems to be having zero effect.

For example, if I hex dump the file, I will see lines such as :

63 6f 6d be 0a 

Obviously, the culprit here is the hex character

be

But running the following pipe

.... | sed 's/[^A-Za-z0-9]//' | hexdump -C

I still see "be" appearing !

1
  • You need the Kleene *. Use sed 's/[^[:alnum:]]*$//' Commented Feb 9, 2015 at 15:52

1 Answer 1

1

You can filter the characters you don't want with tr; in your case

... | tr -d -c '[:print:][:cntrl:]'

-d deletes any character matching the specified characters, -c complements the character sets (so it keeps only what matches in this case), [:print:] matches all printable characters including space, and [:cntrl:] matches control characters (such as carriage return and newline, which you probably want to keep).

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.