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
03-21-2011 09:55 PM
03-21-2011 09:55 PM
A script
aa,bb,cc
aa,cc,dd
cc,dd,ee
ff,zz
dd,aa
the file have many lines, and the content may be duplicated and separated by "," sign . Now if I want to erase some contents in the file
1) if the content is duplicate , then output 1 time
2) the result should be in 1 line.
so my desired output is
aa
bb
cc
dd
ee
ff
zz
can advise what can i do ? thx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2011 10:26 PM
03-21-2011 10:26 PM
Re: A script
check this out:
$ cat file | tr "," "\n" | uniq -u
Hth,
Raj.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2011 11:24 PM
03-21-2011 11:24 PM
Re: A script
but it do not handle duplicate case , that mean the output is deplicate ,
can advise if I want if the data is duplicated then do not output the same data , what can i do ? thx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2011 11:30 PM
03-21-2011 11:30 PM
Re: A script
the |uniq -u seems not work in this case.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2011 01:15 AM
03-22-2011 01:15 AM
Re: A script
You can use uniq -c and cut the numeric first field,
$ cat file | tr "," "\n" | uniq -c | cut -c 1-2
I cant check it now, as don't hv system now.
Hth,
Raj.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2011 01:18 AM
03-22-2011 01:18 AM
Re: A script
man sort
alp$ < 1474162.txt tr ',' '\n' | sort | uniq
aa
bb
cc
dd
ee
ff
zz
alp$
Try it first without the "| uniq".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2011 04:26 AM
03-22-2011 04:26 AM
Re: A script
For 'uniq' to work the stream has to be sorted first
Man...
"DESCRIPTION
Discard all but one of successive identical lines from INPUT"
Here the solution with "tr | sort | uniq" probably works just fine.
For modest dataset you may also want to play with PERL to allow for more tricky splitting, parsing, counting and printing.
In this simple example we can set up an array value for each word found and at the end ( eskimo kiss: }{ :-) print all the keys thus established
$ perl -lne '$x{$_}=1 for split /,/ } { print for (sort keys %x) ' x.txt
aa
bb
cc
dd
ee
ff
zz
fwiw,
Hein
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2011 11:17 AM
03-22-2011 11:17 AM
Re: A script
Here you go with awk,
# cat file | tr "," "\n" | awk '!x[$0]++'
aa
bb
cc
dd
ee
ff
zz
#
Enjoy, Have fun! Remember to assign points to all posts,
Raj.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2011 11:41 AM
03-22-2011 11:41 AM
Re: A script
aa
bb
aa
bb
bb
ran thru uniq, will generate:
aa
bb
aa
bb
not
aa
bb
the one liner should be something like this:
cat file | tr "," "\n" | sort | uniq
Hope this helps
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2011 12:01 PM
03-22-2011 12:01 PM
Re: A script
Geez. Why didn't _I_ think of that. No,
wait...
And my version lacked the (much hated) "cat".
And, when picoseconds count, I figure that
'x' should be faster than "x" -- no looking
for dollar signs in 'x'.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2011 09:10 PM
03-22-2011 09:10 PM
Re: A script
You can optimize this by using "sort -u".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2011 09:57 PM
03-22-2011 09:57 PM
Re: A script
, uniq only senses consecutive lines which were duplicates. sometime I used to wonder why uniq not working properly, now it make sense, t u.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2011 12:18 AM
03-23-2011 12:18 AM
Re: A script
HTH,
Art
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2011 12:47 AM
03-23-2011 12:47 AM