I need to delete all comments inside all script files in the current folder and sub folders. All comment lines start with //. I want to delete the whole line
find . -type f |xargs sed -i '\#^//#d'
the find part find all files, and the sed
part removes all lines starting with //
You can add -name
option in find
to do further filtering. check man find
to get more useful information.
Your pattern contains slash /
, so with sed's default /pattern/d
you have to do some escaping. I used #
as delimiter to save that kind of works, and made the code easier to read.
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.