简体   繁体   中英

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)

您可以使用sed(1)编辑文件:

sed -e 's/#dir2/dir2/' /etc/ironman.d

一个awk解决方案:

awk -F'#' '{print $2}' /etc/ironman.d

替换所有领先的#:

sed -e 's/^#*//' /etc/ironman.d

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM