How can we remove all white spaces from the beginning of the line using tr in bash

advertisements

i know the sed syntax for removing whitespaces from begin of line, can it be done using tr command ?

my file is file.txt like .

    th ht djs
        ncdbh jdhbc ncbs
     hi nc hdn
 mued ndc

after removing all whitespaces from begin we get file like

th ht djs
ncdbh jdhbc ncbs
hi nc hdn
mued ndc


The Answer to your quesition is no. tr doesn't support deletion of specific patterns using regex. The purpose of tr is different - man tr

If you want to use sed:

sed -i -e 's/^[ \t]*//' file.txt