Reputation: 5339
How can I comment out lines where a certain word can be found in a bash script, using piped UNIX commands (no sed/awk) ?
The comment character is #
.
Here is how It could start :
cat $file | grep $word | ...
Upvotes: 2
Views: 177
Reputation: 88646
With GNU bash.
#!/bin/bash
keyword="foo"
while IFS= read -r line; do
[[ "$line" =~ $keyword ]] && line="${line#*#}"
printf "%s\n" "$line"
done < /etc/network/interfaces > /tmp/interfaces_modified
Upvotes: 1