![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| UK businesses shunning real-time data analysis | iBot | Complex Event Processing RSS News | 0 | 07-14-2008 07:30 PM |
| An Introduction to Real-Time Data Integration | iBot | Oracle Updates (RSS) | 0 | 04-06-2008 05:10 AM |
| merging CSV data using a one liner from shell? | jjinca | Shell Programming and Scripting | 2 | 08-13-2007 11:15 AM |
| Need help for 2 data file merging | getdpg | Shell Programming and Scripting | 2 | 07-12-2006 09:07 AM |
| Merging data | ReV | Shell Programming and Scripting | 8 | 06-03-2005 03:14 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
If you have the first output in file1 and the second output in file2:
Code:
awk '
NR==FNR{split($2,s,"/");i=s[2];a[i]=$3;next}
a[$7]{$0=$0 FS a[$7]}
{print}
' file2 file1
Regards |
|
|||||
|
Quote:
A couple questions... Im still learing awk... Can you explain how this works.. What its doing so I dont have to ask about other scripts in the future and I can help others more. really appreciate it. |
|
||||
|
Code:
awk '
NR==FNR{split($2,s,"/");i=s[2];a[i]=$3;next}
a[$7]{$0=$0 FS a[$7]}
{print}
' file2 file1
The code for the first file (file2): Code:
NR==FNR{split($2,s,"/");i=s[2];a[i]=$3;next}
split($2,s,"/") -> we split the second field to get the keys 2, 3 etc. i=s[2] -> i is now the key a[i]=$3 -> create an array "a" with the key as index and assign the value of the 3th field to the array next -> read the next line and skip the rest of the code The code for the second file (file1): Code:
a[$7]{$0=$0 FS a[$7]}
{print}
{print} -> print the line. Hope this helps. Regards |
|
|||||
|
ok there is a problem, there is no check based on time.
I would need to check to see who was logged into the pts/# based on what time it was logged. I know I can do it in perl, but would rather not. if I have: Jul 14 08:02:48 server1 su: - 0 user1-root Jul 14 09:13:23 server1 su: + 0 user1-root Jul 14 12:03:03 server1 su: + 0 user1-root Jul 14 18:15:13 server1 su: + 0 user2-root Jul 14 15:03:01 server1 su: + 0 user7-root and user1 pts/0 10.0.0.1 Thu Jul 14 08:00 - 10:00 (02:00) user1 pts/0 10.0.0.2 Thu Jul 14 11:00 - 13:00 (02:00) user2 pts/0 10.0.0.3 Wed Jul 14 16:00 - 20:00 (04:00) user7 pts/0 hostx Wed Jul 14 13:25 - 15:01 (02:35) I get: Jul 14 08:02:48 server1 su: - 0 user1-root hostx Jul 14 09:13:23 server1 su: + 0 user1-root hostx Jul 14 12:03:03 server1 su: + 0 user1-root hostx Jul 14 18:15:13 server1 su: + 0 user2-root hostx Jul 14 15:03:01 server1 su: + 0 user7-root hostx Last edited by Ikon; 07-17-2008 at 02:56 PM.. |
|
|||||
|
Quote:
Username: "userX" = "userX"-xxxxxxxx pts: pts/"#" = - "#" userX....... Time: ##:##:## within ##:## - ##:## that wont be enough? |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Tags |
| solaris |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|