- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: join problem with awk/printf
Operating System - Linux
1752810
Members
5778
Online
108789
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
тАО07-11-2006 08:04 AM
тАО07-11-2006 08:04 AM
Re: join problem with awk/printf
Hi Scott,
I'm inclined to pursue a wee bit more owing to the intriguing nature of the problem and because imho i think i'ave finally hit the nail on the head :)
1. sort each of the files individually on the first field
# sort -k1,1 /tmp/std_backup_list3 > /tmp/std_backup_list3.out
# sort -k1,1 /tmp/swinfo > /tmp/swinfo.out
2. join the sorted output files from above into a single output file
# join -1 1 -2 1 /tmp/std_backup_list3.out /tmp/swinfo.out > /tmp/all.out
~cheers
I'm inclined to pursue a wee bit more owing to the intriguing nature of the problem and because imho i think i'ave finally hit the nail on the head :)
1. sort each of the files individually on the first field
# sort -k1,1 /tmp/std_backup_list3 > /tmp/std_backup_list3.out
# sort -k1,1 /tmp/swinfo > /tmp/swinfo.out
2. join the sorted output files from above into a single output file
# join -1 1 -2 1 /tmp/std_backup_list3.out /tmp/swinfo.out > /tmp/all.out
~cheers
- Tags:
- Sort
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-11-2006 09:30 AM
тАО07-11-2006 09:30 AM
Re: join problem with awk/printf
have you tried just using a different field separator to do the join?
for example:
sed 's/ /|/g' file1 > file1a
sed 's/ /|/' file2 > file2a
join -t"|" file1a file2a | tr '|' ' '
for example:
sed 's/ /|/g' file1 > file1a
sed 's/ /|/' file2 > file2a
join -t"|" file1a file2a | tr '|' ' '
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-11-2006 04:07 PM
тАО07-11-2006 04:07 PM
Re: join problem with awk/printf
Here is an other approach, similar to Sandman's...
It treats s.txt as a reference file to 'cross' with.
The file b.txt is that backup log.
Awk does all the work, by storing records from the software file in an associative array.
No need to sort... the data will be in the backup log order:
C:\Temp>type s.txt
hostnameA HR development, Data Repository development, crazy stuff, more crazy stuff
hostnameB stupid stuff, more stupid stuff
hostnameD weird stuff, more weird stuff
hostnameE eerie stuff, more eerie stuff
hostnameZ Security Respository stuff, more backup stuff
C:\Temp>type b.txt
hostnameA 0 policy_name date time
hostnameZ 8 good_policy goodday goodtime
hostnameB 1 bad_policy nodate never
hostnameC 2 old_policy someday sometime
C:\Temp>awk 'NR==FNR {key=$1; sub(key,""); S[key]=$0}
NR!=FNR {printf "%-10s\t%s\t%-30s\t%s \n", $1, $2, $3, $4, $5, S[$1]}' s.txt b.txt
hostnameA 0 policy_name date time HR development, Data Repository development, crazy stuff, more cr
azy stuff
hostnameZ 8 good_policy goodday goodtime Security Respository stuff, more backup stuff
hostnameB 1 bad_policy nodate never stupid stuff, more stupid stuff
hostnameC 2 old_policy someday sometime
The awk script decides from which file the data is by comparing the current line number NR with the line in current file number FNR. If they are the same, then it is the first file.
fwiw,
Hein.
It treats s.txt as a reference file to 'cross' with.
The file b.txt is that backup log.
Awk does all the work, by storing records from the software file in an associative array.
No need to sort... the data will be in the backup log order:
C:\Temp>type s.txt
hostnameA HR development, Data Repository development, crazy stuff, more crazy stuff
hostnameB stupid stuff, more stupid stuff
hostnameD weird stuff, more weird stuff
hostnameE eerie stuff, more eerie stuff
hostnameZ Security Respository stuff, more backup stuff
C:\Temp>type b.txt
hostnameA 0 policy_name date time
hostnameZ 8 good_policy goodday goodtime
hostnameB 1 bad_policy nodate never
hostnameC 2 old_policy someday sometime
C:\Temp>awk 'NR==FNR {key=$1; sub(key,""); S[key]=$0}
NR!=FNR {printf "%-10s\t%s\t%-30s\t%s \n", $1, $2, $3, $4, $5, S[$1]}' s.txt b.txt
hostnameA 0 policy_name date time HR development, Data Repository development, crazy stuff, more cr
azy stuff
hostnameZ 8 good_policy goodday goodtime Security Respository stuff, more backup stuff
hostnameB 1 bad_policy nodate never stupid stuff, more stupid stuff
hostnameC 2 old_policy someday sometime
The awk script decides from which file the data is by comparing the current line number NR with the line in current file number FNR. If they are the same, then it is the first file.
fwiw,
Hein.
- « Previous
-
- 1
- 2
- Next »
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