Re: cat or more (891 Views)
Valued Contributor
Posts: 239
Registered: ‎02-18-2002
Message 1 of 4 (905 Views)
Accepted Solution

cat or more

[ Edited ]

Hello to all,


can anyone help me with the command to list the content of a file without lines starting with a "#"


Thanks, Alfons


P.S. This thread has been moved from HP-UX>System Administration to  HP-UX > languages. -HP Forum Moderator

Honored Contributor
Posts: 13,922
Registered: ‎06-21-2000
Message 2 of 4 (891 Views)

Re: cat or more

If you just want to omit lines with the '#' sign in the first column then this will do:


grep -v ^# /some/file


You can also pipe the output to 'more' as well.


grep -v ^# /some/file | more


If you want to list a file without ANY comment lines or blank lines, then try the following:


awk 'NF && ! /^[[:space:]]*#/' /some/file


You can also set the above as an alias so it is easier to use.  For example:


alias noc="awk 'NF && ! /^[[:space:]]*#/'"


Once the alias is set, you can just do:


noc /some/file



(By the way 'noc' means 'no comment')

Valued Contributor
Posts: 239
Registered: ‎02-18-2002
Message 3 of 4 (882 Views)

Re: cat or more

Thanks Patrick,


just what I needed.


Groeten, Alfons

Valued Contributor
Posts: 64
Registered: ‎09-13-2013
Message 4 of 4 (868 Views)

Re: cat or more

And to add to Patrick's solution, the noc alias is a true filter and can be used to read a file or accept stdin, like this:


noc /some/file

swlist -l patch | noc


The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.