Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Replace a hash character in file?

How can I remove '#' character from file

 File Name: /etc/ironman.d

 #dir /usr/comicon
 #dir2 /usr/individuality
 #dir3 /usr/land

How can I remove '#' character before dir2. There is no way to maintain line number. I tried

 dirpath='#dir2 /usr/individuality'
 ${dirpath#/#}

But it only removes in $dirpath but not in actual file, if I use above method to remove '#' and add then, I get a duplicate of $dirpath without '#', but I just want single entry without '#' in the file. How do I remove # in place (before dir2)

like image 291
run_time_rookie Avatar asked Sep 13 '25 11:09

run_time_rookie


1 Answers

You can use sed(1) to edit files:

sed -e 's/#dir2/dir2/' /etc/ironman.d
like image 107
Carl Norum Avatar answered Sep 16 '25 04:09

Carl Norum