Re: cat or more (279 Views)
Reply
Regular Advisor
A.G.M. Velthof
Posts: 218
Registered: ‎02-18-2002
Message 1 of 4 (316 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
Patrick Wallek
Posts: 13,774
Registered: ‎06-21-2000
Message 2 of 4 (302 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')

Regular Advisor
A.G.M. Velthof
Posts: 218
Registered: ‎02-18-2002
Message 3 of 4 (293 Views)

Re: cat or more

Thanks Patrick,

 

just what I needed.

 

Groeten, Alfons

Frequent Advisor
pooderbill
Posts: 42
Registered: ‎09-13-2013
Message 4 of 4 (279 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.