- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- question on grep
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
Forums
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
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
тАО07-30-2010 01:47 PM
тАО07-30-2010 01:47 PM
question on grep
what options should i use to grep a pattern in the file ,the entries in the file looks like below
df,gh,ww:user name:home dir
gh:user name :home dir
ww,gh:username:home dir
i need to grep a entry that does have only a gh in the first column
any idea , much appreciated
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-30-2010 01:59 PM
тАО07-30-2010 01:59 PM
Re: question on grep
"Only gh in the first field" is equal to
So, the command would be:
grep '^gh:' somefile
MK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-30-2010 02:04 PM
тАО07-30-2010 02:04 PM
Re: question on grep
man regexp
dyi # echo 'gh:user' | grep '^gh'
gh:user
dyi # echo 'df,gh,ww:user' | grep '^gh'
dyi #
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-30-2010 02:15 PM
тАО07-30-2010 02:15 PM
Re: question on grep
If the columns are delimited with ":" delimiters, you could use:
# awk -F: '$1~/gh/ {print}' file
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-30-2010 02:31 PM
тАО07-30-2010 02:31 PM
Re: question on grep
- You can do it with awk:
$ awk -F ":" '{if ($1 ~ /gh/ ) print $0}' file_name
Example:
$ cat file_name
df,gh,ww:user name:home dir
gh:user name :home dir
ww,gh:username:home dir
ww,fh:username:home dir
ww,dh:username:home dir
$ awk -F ":" '{if ($1 ~ /gh/ ) print $0}' filename
df,gh,ww:user name:home dir
gh:user name :home dir
ww,gh:username:home dir
Cheers,
Raj.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-30-2010 03:04 PM
тАО07-30-2010 03:04 PM
Re: question on grep
> If the columns [...]
As usual, a more precise definition of the
problem might reduce the guesswork, and lead
to more accurate answers.
> [...] a gh in the first column
Define "column". Here, "g" is "in the first
column". "h" is in the second column. Are
you looking for "gh" which begins in column
one, or what, exactly?
Are you worried about columns, or
colon-separated fields, or what, exactly?