- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: How to select a string from a file
Operating System - HP-UX
1753899
Members
7694
Online
108809
Solutions
Forums
Categories
Company
Local Language
юдл
back
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
юдл
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- 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
тАО10-21-2008 11:30 AM
тАО10-21-2008 11:30 AM
I have a file (file1) containing unique numbers, that I want to use to extract information from another file (file2).
file1 has the following contents -
14
15
20
201
202
file2 has the following text -
RaidGroup ID 14 Logical Capacity 23456 Free Capacity 12345
RaidGroup ID 20 Logical Capacity 23456 Free Capacity 12341
RaidGroup ID 204 Logical Capacity 23456 Free Capacity 12342
RaidGroup ID 202 Logical Capacity 23456 Free Capacity 12343
RaidGroup ID 2 Logical Capacity 23456 Free Capacity 12344
For each entry in file1 (which is field 3 in file2), I have to extract Free Capacity from file2. How do I structure my query so that when I awk for 20, I don't get results for 202 & 204 as well.
for x in `cat file1`
do
awk '$3 ~ /$x/' file2|awk '{print $NF}'
# The above line also gives error
done
Thanks.
file1 has the following contents -
14
15
20
201
202
file2 has the following text -
RaidGroup ID 14 Logical Capacity 23456 Free Capacity 12345
RaidGroup ID 20 Logical Capacity 23456 Free Capacity 12341
RaidGroup ID 204 Logical Capacity 23456 Free Capacity 12342
RaidGroup ID 202 Logical Capacity 23456 Free Capacity 12343
RaidGroup ID 2 Logical Capacity 23456 Free Capacity 12344
For each entry in file1 (which is field 3 in file2), I have to extract Free Capacity from file2. How do I structure my query so that when I awk for 20, I don't get results for 202 & 204 as well.
for x in `cat file1`
do
awk '$3 ~ /$x/' file2|awk '{print $NF}'
# The above line also gives error
done
Thanks.
work is fun ! (my manager is standing behind me!!)
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-21-2008 11:51 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-21-2008 12:10 PM
тАО10-21-2008 12:10 PM
Re: How to select a string from a file
Bull's Eye! Thanks JRF!
Here is the quick solution -
for x in `cat file1`
do
awk -v x=$x '$3==x' file2
done
Thanks again.
Here is the quick solution -
for x in `cat file1`
do
awk -v x=$x '$3==x' file2
done
Thanks again.
work is fun ! (my manager is standing behind me!!)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-21-2008 02:50 PM
тАО10-21-2008 02:50 PM
Re: How to select a string from a file
> [...] so that when I awk for 20, I don't
> get results for 202 & 204 as well.
Including some white space in your search
string can help, too.
dy # x=20
dy # grep "$x" file2
RaidGroup ID 20 Logical Capacity 23456 Free Capacity 12341
RaidGroup ID 204 Logical Capacity 23456 Free Capacity 12342
RaidGroup ID 202 Logical Capacity 23456 Free Capacity 12343
dy # grep " $x " file2
RaidGroup ID 20 Logical Capacity 23456 Free Capacity 12341
> get results for 202 & 204 as well.
Including some white space in your search
string can help, too.
dy # x=20
dy # grep "$x" file2
RaidGroup ID 20 Logical Capacity 23456 Free Capacity 12341
RaidGroup ID 204 Logical Capacity 23456 Free Capacity 12342
RaidGroup ID 202 Logical Capacity 23456 Free Capacity 12343
dy # grep " $x " file2
RaidGroup ID 20 Logical Capacity 23456 Free Capacity 12341
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP