- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- uncommneted Lines in files
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-15-2011 06:39 PM
тАО03-15-2011 06:39 PM
i have a file in hpux 11.23 and having 500 Lines in that file ,some of the lines are commented and some of the lines are uncommented .what is the simple command to show only commented /uncommented lines in this file ?
rgds,trng
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-15-2011 06:50 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-15-2011 08:38 PM
тАО03-15-2011 08:38 PM
Re: uncommneted Lines in files
Not a very detailed description of anything.
Define "commented". Commented as in a shell
script? Commented as in C code? C++?
Fortran? Pascal? DCL?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-16-2011 05:00 AM
тАО03-16-2011 05:00 AM
Re: uncommneted Lines in files
If by "commented' you mean with the '#' then this will find lines where the first non-whitespace character is a '#':
# grep ^[[:space:]]*# file
...or those that are non commented-out:
# grep -v ^[[:space:]]*# file
Notice that leading whitespace before the '#' is optional.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-16-2011 06:03 AM
тАО03-16-2011 06:03 AM
Re: uncommneted Lines in files
So here are techniques for handling each condition. It is assumed that each line has been assigned to the variable TEXT:
Skip blank lines:
[[ "$(echo $TEXTLINE | awk NF)" = "" ]] &&
continue
Skip "#" in column 1 only:
[[ $(echo "$TEXTLINE" | grep -cv "^#") -gt 0 ]] &&
continue
Skip "#" even if preceded by whitespace:
echo "$TEXTLINE" | read WORD1 REST
[[ "$(echo "$WORD1" | cut -c1 )" = "#" ]] &&
continue
I have attached a script called NOcomment which will list files without leading "#" characters, or if you run NOcomment with -1 (minus one), it will only look for # in column 1 (much faster). NOcomment accepts stdin or filename(s) on the command line.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-16-2011 06:14 AM
тАО03-16-2011 06:14 AM
Re: uncommneted Lines in files
> Bill: Doug's solution will work fine -- as long as your files ALWAYS have # in column 1.
And that was the whole point of my suggestion to use:
# grep ^[[:space:]]*# file
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-16-2011 06:24 AM
тАО03-16-2011 06:24 AM
Re: uncommneted Lines in files
awk NF filename | grep -v ^[[:space:]]*#
This will remove blank lines and any line with a # as the first non-whitespace character.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-16-2011 04:02 PM
тАО03-16-2011 04:02 PM
Re: uncommneted Lines in files
In the spirit of TMTOWTDI, if we want to treat as "comments" both blank lines and those whose first non-whitespace character is "#", then we could do:
# awk '/^[[:space:]]*(#|$)/' file
...or to find lines that are _not_ comments by this definition:
# awk '! /^[[:space:]]*(#|$)/' file
Regards!
...JRF...