- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- problem with parser
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
тАО06-10-2008 12:03 AM
тАО06-10-2008 12:03 AM
file1:
5555:56:00 789 A
3345:56:18 189 B
1245:56:38 389 A
0045:56:58 689 S
0045:55:51 000 Q
1245:56:44 989 E
2245:56:11 089 E
file2
1245
0045
output:
1245:56:38 389 A
0045:56:58 689 S
0045:55:51 000 Q
I tryed something with comm and join command but I mess myself..
thank you guys
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-10-2008 12:05 AM
тАО06-10-2008 12:05 AM
Re: problem with parser
output:
1245:56:38 389 A
0045:56:58 689 S
0045:55:51 000 Q
1245:56:44 989 E
I forgot last line :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-10-2008 12:18 AM
тАО06-10-2008 12:18 AM
Re: problem with parser
I could do it this way...but takes a lot of time for my big files..
for file in $(< file2); do
grep $file file1 >> myoutout
done
any quicker way?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-10-2008 12:23 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-10-2008 01:37 AM
тАО06-10-2008 01:37 AM
Re: problem with parser
anyways anyone knows better way to optimise this:
join -1 1 -2 1 -t':' -o 2.1,2.2,2.3 file2 file1
thanks everyone.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-10-2008 01:42 AM
тАО06-10-2008 01:42 AM
Re: problem with parser
>for file in $(< file2); do grep $file file1
You can do it in one shot:
fgrep -f file2 file1
This works if the strings in file2 don't appear in other columns of your data. If they do, you may have to add a "^" (and use grep) at the beginning of each line in file2.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-10-2008 01:44 AM
тАО06-10-2008 01:44 AM
Re: problem with parser
Or you're telling us how to not do it. ;-)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-10-2008 02:45 AM
тАО06-10-2008 02:45 AM
Re: problem with parser
thank U very very much
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-10-2008 03:52 AM
тАО06-10-2008 03:52 AM
Re: problem with parser
$ awk 'BEGIN{while (getline line<"file2"){file2[line]=1}} file2[substr($0,1,4)]' file1
1245:56:38 389 A
0045:56:58 689 S
0045:55:51 000 Q
1245:56:44 989 E
In the BEGIN section we read "file2" and set an array element with the key being the entire line to be true.
The main section consists of just a test for the array element in file2 identified by the first 4 characters in each line.
awk beginners might write that 'main' part as:
{ key = substr($0,1,4); if (file2[key]==1) { print } }
Cheers,
Hein.