Wednesday, April 27, 2011

SED command to remove junk characters at first position

If you want to remove the first letter in each line of a file, use SED command. If you want to delete junk characters or special characters occurence in a file, use the below SED command.


$ cat > file1
#23ab
@abc3
%gfdg
`ggfj

$ cat file1 | sed -e 's/^[^0-9A-Za-z]//'
23ab
abc3
gfdg
ggfj

If the special or junk characters appear at twice or thrice, repeat the SED command again over the previous output.



2 comments:

  1. SED to remove junk character
    http://www.chennaigangsters.in/technical-informations-technical-doubts

    ReplyDelete