- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: getting output using awk
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
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
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
01-16-2004 12:08 AM
01-16-2004 12:08 AM
I have an awk script that actually parse the fields in the file but my problem is, I must get/grep the field value in another file.
My script looks like this:
awk '{FIELD1=$1; FIELD2=$2;
printf ("%15s %10s", FIELD1, FIELD2)}' FILE1
I wanted to get/grep the FIELD2 from FILE2 in order to get another data from FILE2, how do I get it?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2004 12:37 AM
01-16-2004 12:37 AM
Re: getting output using awk
s1=sprintf(" grep %s FILE2",FIELD2);
system(s1);
Note for each FIELD2 it will generate a process grep
Rgds,
Jean-Luc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2004 12:54 AM
01-16-2004 12:54 AM
Re: getting output using awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2004 02:45 AM
01-16-2004 02:45 AM
Re: getting output using awk
Example-
join -j1 1 -j2 1 -o 1.1,2.2 | awk ...
This would send the common key field for file1 and file2 and the second field of file2 to awk.
"join" works like a SQL join, treating the 2 text files like tables.
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2004 07:47 PM
01-19-2004 07:47 PM
Re: getting output using awk
Join works fine but I need find the matched
of field2 from file2 using awk.
My FILE1 have these fields:
12345 20
12346 30
My FILE2 have these fields:
20 hello
30 thanks
What I want is to get the string "hello" or "thanks" in my awk.
The output will be something like these:
12345 20 hello
12346 30 thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2004 08:22 PM
01-19-2004 08:22 PM
Re: getting output using awk
cat file2 | while read indx word
do
indx2=""
cat file1 | while read field1 indx2
do
if [ $indx -eq $indx2 ]
then
echo "$field1 $indx $word"
fi
done
done
file1:
12345 20
12346 30
file2
20 hello
30 thanks
Output:
12345 20 hello
12346 30 thanks
Regards,
Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2004 08:27 PM
01-19-2004 08:27 PM
Re: getting output using awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2004 11:18 PM
01-19-2004 11:18 PM
Re: getting output using awk
If one is small, it may be possible to fill an array with the values and then process each line of the large file, looking up the value in the array.
If both are large, sort both files on the field they have in common. Then read both files, advancing in a file if the common field is less than the field of the current line of the other file.
This may be tricky in awk.
JP.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2004 01:16 AM
01-20-2004 01:16 AM
Re: getting output using awk
cat FILE2
echo --- starting data ---
cat FILE1
) awk '/--- starting data ---/ {infile1=1}
infile1==0 { response[$1]=$2 }
infile1==1 { printf("%15s %10s %s\n",$1,$2,response[$2]);}'
This should do the trick...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2004 05:44 AM
01-20-2004 05:44 AM
Re: getting output using awk
looks nice. Wonder what Florinda thinks (and awards?)
JP.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2004 05:20 PM
01-20-2004 05:20 PM
SolutionFlorinda, if you check my solutions, put a pipe ('|') between the closing bracket ('}') and awk, otherwise it won't work (and complain about a syntax error).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2004 07:31 PM
01-20-2004 07:31 PM
Re: getting output using awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2004 09:08 PM
01-20-2004 09:08 PM
Re: getting output using awk
How about if my files are something like these:
::::::::::::::
FILE1
::::::::::::::
12345 123 123 20
12346 123 123 30
12347 123 123 20
12348 123 123 90
::::::::::::::
FILE2
::::::::::::::
20 hello
30 thanks
OUTPUT IS:
12345 123 123 20 hello
12346 123 123 30 thanks
12347 123 123 20 hello
12348 123 123 90
Sorry I'm very new in using awk.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2004 09:28 PM
01-20-2004 09:28 PM
Re: getting output using awk
'infile1==1 { printf("%15s %10s %s\n",$1,$2,response[$2]);}'
with
'infile1==1 { printf("%s %s\n",$0,response[$NF]);}'
This will work, no matter how many fields are in FILE1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2004 10:10 PM
01-20-2004 10:10 PM
Re: getting output using awk
#!/usr/contrib/bin/perl
open(FILE2, $ARGV[1]);
while(
($field1, $field2)=split;
$map{$field1}=$field2;
}
close(FILE2);
open(FILE1, $ARGV[0]);
while(
chop;
@l=split;
print "$_ $map{$l[$#l]}\n";
}
close(FILE1);