Remove Occurrences created with Uniq -c


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Remove Occurrences created with Uniq -c
# 1  
Old 04-07-2011
Remove Occurrences created with Uniq -c

Hello,
I have "mastered" the counting of occurrences with uniq -c. Smilie
Now I need to keep that file neat and nice and remove only the occurrence number and the space after it.
Example:
Code:
1286456   aaa
164758     aab aaa 
112345     aac aaf

should be turned into:
Code:
aaa
aab aaa
aac aaf

I have tried without too much success "cut" and was pointed towards awk and sed, alas ... I am posting in the dummy section for a reason...

Code:
awk {'print $2'} foobar.txt > foobar_1.txt     #also removes the spaces included in the lines

And
Code:
sed 's/^\ \+[0-9]\+\ //' foobar.txt > foobar_1.txt[/I]  # does not work (I was told that I have FreeBSD and not GNU sed)

Does anyone could point me in the right direction?

Thank you very much in advance.

Last edited by Scott; 04-07-2011 at 08:34 PM.. Reason: Please use code tags
# 2  
Old 04-07-2011
Try:
Code:
cut -d" " -f2- foobar.txt > foobar_1.txt

# 3  
Old 04-07-2011
Thanks for the reply, but cut does not do it ~completely~
Code:
cut -d" " -f2- foobar.txt > foobar_1.txt

Only removes the occurrence count from up to 4 digit
After that, it leaves all the 999 to 1
It seems that uniq shift the count to the right to align it, hence you end up with one, two or three spaces before the count.

Example after using cut
Code:
aaa
aab
aac
 999 aad
  99 aaf


Last edited by Scott; 04-07-2011 at 08:35 PM.. Reason: Use code tags to preserve formatting
# 4  
Old 04-08-2011
Code:
perl -pe 's/^\s*\d+\s+//' foobar.txt > foobar_1.txt

This User Gave Thanks to bartus11 For This Post:
# 5  
Old 04-08-2011
why don't you just remove the "-c" option to uniq?
# 6  
Old 04-08-2011
I agree ...

+1 for binlib
# 7  
Old 04-08-2011
Bartus11,
Thank you very much, it worked like a charm. Your help is really appreciated.
Kudos to you.

---------- Post updated at 09:07 AM ---------- Previous update was at 08:52 AM ----------

Binlib,
Sorting with occurrence count & removing duplicates is what I was looking for.
Code:
sort | uniq -c | sort -nr

is giving you a count by occurrence, highest first, and removes the duplicates.
removing -c on uniq was not an option

Another possibility is
Code:
awk {'print $2'} foobar.txt > foobar_1.txt

but it will remove all spaces, including the ones contained in the lines.

Thanks to all for your input.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Can you do remove core file based on what created them :(

Hi, Currently, we have a Perl script from a third-party vendor that is generating core dumps. It has been reported. We can't turn off the script as it does generate some diagnostic file that's required. So at the moment, we have to let it continue to do its run. I wish I can say the vendor is... (8 Replies)
Discussion started by: newbie_01
8 Replies

2. Shell Programming and Scripting

Remove duplicate occurrences of text pattern

Hi folks! I have a file which contains a 1000 lines. On each line i have multiple occurrences ( 26 to be exact ) of pattern folder#/folder#. # is depicting the line number in the file some text here folder1/folder1 some text here folder1/folder1 some text here folder1/folder1 some text... (7 Replies)
Discussion started by: martinsmith
7 Replies

3. Shell Programming and Scripting

Show "uniq -c" results only for more than X occurrences

Say I have test.txt with the following data: user1 mailbox11 IP1 user1 mailbox12 IP2 user2 mailbox21 IP1 user3 mailbox31 IP1 user1 mailbox11 IP1 user1 mailbox11 IP1 user1 mailbox11 IP1 user1 mailbox12 IP2 user2 mailbox21 IP1 user2 mailbox21 IP1 user2 mailbox21 IP1 user2 mailbox21 IP1... (4 Replies)
Discussion started by: striker4o
4 Replies

4. Shell Programming and Scripting

Script to remove folders by date created

Hi All I require to generate a script that deletes folders and sub directoires from a set period after creation. So have folder X on a daily basis i have job folders being created folder name 1234568. What i need to do is keep this folder pruned. So say 7 days after creation of the job folder its... (4 Replies)
Discussion started by: treds
4 Replies

5. Shell Programming and Scripting

remove all occurrences of a character at the beginning of a string

Hi there, i need some help to remove all occurrences of a certain character at the beginning of a string. Example: my string is 00102030 and i want to remove all zeros from beginning of string so the result is 102030 (3 Replies)
Discussion started by: gigagigosu
3 Replies

6. Shell Programming and Scripting

[uniq + awk?] How to remove duplicate blocks of lines in files?

Hello again, I am wanting to remove all duplicate blocks of XML code in a file. This is an example: input: <string-array name="threeItems"> <item>item1</item> <item>item2</item> <item>item3</item> </string-array> <string-array name="twoItems"> <item>item1</item> <item>item2</item>... (19 Replies)
Discussion started by: raidzero
19 Replies

7. Shell Programming and Scripting

How remove the file which was created by another user?

When I try to remove the file which was created by another user through super user, I am getting the "override protection 644 " meesage. Could you please anyone help me how will I delete the file without prmpting the override protection. I have also given the permission (rwx) to the group as... (3 Replies)
Discussion started by: kandi.reddy
3 Replies

8. UNIX for Advanced & Expert Users

remove lines from file where > 13 occurrences of character

I have a '~' delimited file of 6 - 7 million rows. Each row should contain 13 columns delimited by 12 ~'s. Where there are 13 tildes, the row needs to be removed. Each row contains alphanumeric data and occasionally a ~ ends up in a descriptive field and therefore acts as a delimiter, resulting... (7 Replies)
Discussion started by: kpd
7 Replies

9. Shell Programming and Scripting

Remove files which created date before 10 days on HP-UX

Hi All, Could you please let me know if there is any one can help to create a shell script to remove some files which is the created date for them greate than 10 days (sysdate-10) Please try to email me on email removed Thanks in advance, Murad (1 Reply)
Discussion started by: murad_fayez
1 Replies

10. UNIX for Dummies Questions & Answers

find and remove rows from file where multi occurrences of character found

I have a '~' delimited file of 6 - 7 million rows. Each row should contain 13 columns delimited by 12 ~'s. Where there are 13 tildes, the row needs to be removed. Each row contains alphanumeric data and occasionally a ~ ends up in a descriptive field and therefore acts as a delimiter, resulting in... (1 Reply)
Discussion started by: kpd
1 Replies
Login or Register to Ask a Question