I need to make a shell script that displays config files without the commented and empty lines

Ask Ubuntu Asked by I don't like shell script on November 21, 2020

This is my code:

echo "Type in your file"
read file
sed -r -e 's/(^[^#]*$) ; s/(^[^;]*$) ; s/(^[^$]*$) ; s/(^[^/]*$) ; s/(^[^ ]*$)' $file

This is the output when I give it a file:

sed: -e expression #1, char 31: unknown option to `s’

Why am I getting this error? Would you suggest another way to do it?
Thanks in advance

2 Answers

Should remove most comments and empty lines:

pcre2grep -v '^[[:blank:]]*([#;]|//|$)' file

Answered by bac0n on November 21, 2020

This might help more:

grep -Ev '^s+$|^#' file.txt

Answered by waltinator on November 21, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP