Arpitha M
Arpitha M

Reputation: 85

To remove only junk characters from a text file in linux

I have a text file which contains folder and file names with junk characters inserted in between. I want to filter only folder names, below is an example:

/TEST/C/Users/Account/Documents/T/Java/Reach/con/trail-and-error/modify/web/jk/args-pasre/library/°/°/°/°/°/°/°/°/°/°/°/key-check-folat.js

I want my output to be:

/TEST/C/Users/Account/Documents/T/Java/Reach/con/trail-and-error/modify/web/jk/args-pasre/library/key-check-folat.js

Tried doing below, but it removes "/" and "-" characters from list.

echo "/TEST/C/Users/Account/Documents/T/Java/Reach/con/trail-and-error/modify/web/jk/args-pasre/library/°/°/°/°/°/°/°/°/°/°/°/key-check-folat.js" | tr -cd '[:alnum:]'

Upvotes: 0

Views: 407

Answers (1)

sinkmanu
sinkmanu

Reputation: 1102

With sed:

$ echo "/TEST/C/Users/Account/Documents/T/Java/Reach/con/trail-and-error/modify/web/jk/args-pasre/library/°/°/°/°/°/°/°/°/°/°/°/key-check-folat.js" | sed 's/\/°//g'
/TEST/C/Users/Account/Documents/T/Java/Reach/con/trail-and-error/modify/web/jk/args-pasre/library/key-check-folat.js

Upvotes: 1

Related Questions