- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- scripting question - 2
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
08-12-2002 11:25 PM
08-12-2002 11:25 PM
scripting question - 2
Im trying my best to make an awk program that could read a file and display only lines that are unique. The input file is a file with atleast 2000 lines some of the lines are the same. Could somebody help me on how to approach this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2002 11:29 PM
08-12-2002 11:29 PM
Re: scripting question - 2
I assume that you really want to do this with awk only? Could be a litte bit hard, I think.
Couldn't you just pipe through uniq or sort -u before going to awk?
Regards...
Dietmar.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2002 11:46 PM
08-12-2002 11:46 PM
Re: scripting question - 2
Although I agree that this is probably best done with sort -u, if you want to confine it to awk you could use an array to store all the lines with $0 as the name of each element. That way, when awk goes to assign a value to the array element and that line had already been assigned, it will just be overwritten. You'll end up with unique lines.
{
myarray[$0] = $0
}
END {
for ( line in myarray ) { print line )
}
The difference will be that awk will return the lines in no particular order (it will not necisarily return them in the order it read them in).
Simon.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2002 11:48 PM
08-12-2002 11:48 PM
Re: scripting question - 2
{
myarray[$0] = $0
}
END {
for ( line in myarray ) { print line }
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2002 11:49 PM
08-12-2002 11:49 PM
Re: scripting question - 2
Perhaps you should look at the command "uniq" (man uniq).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2002 11:53 PM
08-12-2002 11:53 PM
Re: scripting question - 2
Ofcourse it only compares adjacent lines...
You might wanna compare this with the other solutions like sort -u.
Regards,
Ceesjan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2002 12:09 AM
08-13-2002 12:09 AM
Re: scripting question - 2
# perl -ne '$x{$_}++;END{for$x(keys%x){$x{$x}==1&&print$x}' infile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2002 08:01 PM
08-14-2002 08:01 PM
Re: scripting question - 2
If you want to retain the original order, try
perl -ne 'push@a,$_;$h{$_}++;END{foreach(@a)print unless$h{$_}>1}}' infile
or in awkese
awk '{a[NR]=$0;h[$0]++;}END{for(i=1;i<=NR;i++){if(h[a[i]]==1)print a[i]}}'infile
Cheers,
JW.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2002 11:25 PM
08-14-2002 11:25 PM
Re: scripting question - 2
awk '{a[$0]++}END{for(l in a){if(a[l]==1){print l}}}' filename
Rgds, Robin