HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- what awk statement to use?
Operating System - Linux
1827868
Members
889
Online
109969
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
Forums
Discussions
Discussions
Discussions
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
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
04-01-2008 02:00 AM
04-01-2008 02:00 AM
Hi,
I have a file with 12 rows and I want to use awk to search a second file with that particular string:
file to search is pcm.out
file with data to be searched is disk.lst
so i am looking for a way so that data in disk.lst can be founf in pcm.out.
I was kinda thinking:
awk '$1 ~ /$0/ {print}' pcm.out disk.lst
this dont work ....
any help please?
I have a file with 12 rows and I want to use awk to search a second file with that particular string:
file to search is pcm.out
file with data to be searched is disk.lst
so i am looking for a way so that data in disk.lst can be founf in pcm.out.
I was kinda thinking:
awk '$1 ~ /$0/ {print}' pcm.out disk.lst
this dont work ....
any help please?
hello
Solved! Go to Solution.
- Tags:
- awk
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2008 02:12 AM
04-01-2008 02:12 AM
Solution
You need to give an example of the two files.
You want to take each of the 12 lines in the first file and find a line in the second that has that line plus a few more fields?? (Or you want to find an exact match?)
If so you can use:
fgrep -f disk.lst pcm.out
You want to take each of the 12 lines in the first file and find a line in the second that has that line plus a few more fields?? (Or you want to find an exact match?)
If so you can use:
fgrep -f disk.lst pcm.out
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2008 04:03 AM
04-01-2008 04:03 AM
Re: what awk statement to use?
Does it have to be awk? (why?)
What constitues a match? anywhere on the line? First field? Leading whitespace optional?
Dennis shows the classic grep solution.
You can do something really similar, buf not the same, with awk.
create disk.lst with slashes surrounding the target strings:
/string1/
/string2/
:
/last-string/
now run as
awk -f disk.lst pgm.out.
What you really did here is write a minimalistics awk program with as many conditionals/expressions as there are lines and the expression being defaulted to {print $0}.
Note. For the awk program 'disk.lst', just like in the grep case, the pieces of string are regular expressions.
So a "." matched anything and so on.
hth,
Hein.
What constitues a match? anywhere on the line? First field? Leading whitespace optional?
Dennis shows the classic grep solution.
You can do something really similar, buf not the same, with awk.
create disk.lst with slashes surrounding the target strings:
/string1/
/string2/
:
/last-string/
now run as
awk -f disk.lst pgm.out.
What you really did here is write a minimalistics awk program with as many conditionals/expressions as there are lines and the expression being defaulted to {print $0}.
Note. For the awk program 'disk.lst', just like in the grep case, the pieces of string are regular expressions.
So a "." matched anything and so on.
hth,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2008 05:15 AM
04-01-2008 05:15 AM
Re: what awk statement to use?
ok thanks chaps - I need to take the blinkers off as I knew this solution just couldnt think of it!!
Chris.
Chris.
hello
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.
Company
Support
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP