How to show only uncomment line in the file.
Can anyone tell my, How to list file content and that line not contain # begin, thank.
|
$ cat <file> | grep -v "^ *#"
or $ grep -v "^ *#" <file> this should do the trick, or sed ... $ sed '/^ *#/d' <file> This also ignores leading spaces, removes a line that starts with *any* number of spaces than a comment. If you don't want that you can remove the star from all those line. The "^" means a start of line, the star means zero or more characters, so " *#" means a start of line with zero or more spaces followed by "#". The "-v" in grep tells grep to remove those lines, and the d in sed tells sed to delete those lines. So if you only like to see those line you could leave out the "-v" in grep. Hope that helps. |
Maybe something like grep may help e.g.
Code:
$grep -i ^[A-Z] somefile |
Thank, but not useful in this case.
My file test.txt Code:
post-proxy { Code:
post-proxy { Code:
[root@hotspot ~]# cat test.txt | grep -v "^ *#" Code:
[root@hotspot ~]# grep -v "^ *#" test.txt Code:
[root@hotspot ~]# sed '/^ *#/d' test.txt Code:
[root@hotspot ~]# grep -i ^[A-Z] test.txt |
grep -v "#" test.txt works..
|
Hmm, can't see why those commands I posted are not working for you.
Code:
helgi@desktop:~$> cat > somefile << "EOF" EDIT: Is it possible that those comments are just some long lines that don't start with a newline? Try $ sed 's/^/_/g' <somefile> - and you should see a "_" in the beginning of every line, I think this is your problem, this command should verify that :) |
@helgiks, what's this
Code:
[root@hotspot ~]# cp test.txt test2.txt |
Maybe there are tabs at the beginning of comment lines. You can try this
Code:
sed '/^[\t ]*#/d' test.txt |
It's work, thank you very much.
Code:
[root@hotspot ~]# sed '/^[\t ]*#/d' test.txt |
Ah, there it is...
Than this should do it for you Code:
$ grep -v "^[[:space:]]*#" <file> |
All times are GMT -5. The time now is 02:54 AM. |