sed & remove duplicates on output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed & remove duplicates on output
# 1  
Old 09-24-2012
sed & remove duplicates on output

PHP Code:
sed -'1d' -'s/^\([[:digit:]]\{2\}\)-\([[:digit:]]\{3\}\)-\([[:digit:]]\{4\}\).*/"0000020\1\200\3"\,/g' abc.txt 
This script returns many duplicates due to the duplciates in the .txt file.

i.e.

HTML Code:
...
"000002012149000060",
"000002012149000064",
"000002012149000064",
"000002012149000064",
"000002012149000064",
"000002012149000064",
"000002012149000064",
"000002012149000064",
"000002012149000065",
"000002012149000065",
"000002012149000065",
"000002012149000065",
"000002012149000066",
"000002012149000066",
"000002012149000066",
...
I want to have unique values/outputs so that I can have without duplicates i.e.
HTML Code:
...
"000002012149000060",
"000002012149000064",
"000002012149000065",
"000002012149000066",
...
Please advise.
# 2  
Old 09-24-2012
Code:
sort | uniq < file

# 3  
Old 09-24-2012
Duplicates are contiguous, aren't they? If so, pipe the sed output to uniq command.
Code:
sed ... | uniq

--
Bye
# 4  
Old 09-24-2012
Duplicates are not always contiguous.

I tried:
PHP Code:
sed ... | uniq  abc.txt 
sed 
... sort uniq abc.txt 
sed 
... |sort uniq abc.txt 
but,
PHP Code:
's/^\([[:digit:]]\{2\}\)-\([[:digit:]]\{3\}\)-\([[:digit:]]\{4\}\).*/"0000020\1\200\3"\,/g 
is not working, and it just pulls out the rows as they are in the abc.txt.

Please advise.
# 5  
Old 09-24-2012
try this

Code:
sed ... | sort | uniq

# 6  
Old 09-24-2012
Quote:
Originally Posted by pamu
try this

Code:
sed ... | sort | uniq

I have tried this already, but it pulls out all the rows as they are in the .txt.
Please advise.
# 7  
Old 09-24-2012
try this
Code:
sed ... file | sort | uniq

This User Gave Thanks to pamu For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove duplicates

Hi I have a below file structure. 200,1245,E1,1,E1,,7611068,KWH,30, ,,,,,,,, 200,1245,E1,1,E1,,7611070,KWH,30, ,,,,,,,, 300,20140223,0.001,0.001,0.001,0.001,0.001 300,20140224,0.001,0.001,0.001,0.001,0.001 300,20140225,0.001,0.001,0.001,0.001,0.001 300,20140226,0.001,0.001,0.001,0.001,0.001... (1 Reply)
Discussion started by: tejashavele
1 Replies

2. Shell Programming and Scripting

Trim sed output & assign to variable

Hi, I have the following command that parses an xml file to read a node <port>'s value. Hoever the output comes with spaces. My requirement is to trim the spaces around the value and assign to a variable. sed -n 's|<port>\(.*\)</port>|\1|p' ../cfg.xml How do I go about it? (6 Replies)
Discussion started by: sai2013
6 Replies

3. Shell Programming and Scripting

Grep & sed - Output

Hi All, Facing an issue with grep & sed I have logs as below: gsc_1_20121121.log:2012-11-21 10:09:13,143 INFO - fmsspace.1 ProcessNewOrderSingleRequest: Result - ProcessNewOrderSingleBatchResultDTO - success:true,newOrderSingleBatchResults:ProcessNewOrderSingleResultDTO -... (13 Replies)
Discussion started by: irfanmemon
13 Replies

4. Shell Programming and Scripting

Want to sort a file using awk & sed to get required output

Hi All, Need Suggestion, Want to sort a file using awk & sed to get required, output as below, such that each LUN shows correct WWPN and FA port Numbers correctly: Required output: 01FB 10000000c97843a2 8C 0 01FB 10000000c96fb279 9C 0 22AF 10000000c97843a2 8C 0 22AF 10000000c975adbd ... (10 Replies)
Discussion started by: aix_admin_007
10 Replies

5. Shell Programming and Scripting

Remove duplicates based on query and subject fields from blast output file

Hi all I have a blast outfile file like this : NZ_1540841_1561981 ICMP_1687819_1695946 92.59 27 2 0 12826 12852 3136 3162 0.28 38.2 NZ_1540841_1561981 ICMP_1687819_1695946 95.65 23 1 0 12268 12290 5815 5837 0.28 38.2 NZ_1540841_1561981 ICMP_3674888_3676546 82.70 185 32 0 9454 9638 11 195 6e-24 ... (2 Replies)
Discussion started by: pbioinfo
2 Replies

6. UNIX for Dummies Questions & Answers

sed remove expression from output I'm watching

I'm watching a particular expression as it is appended in a line to a file: tail -f LOG | sed -n /"$@"/p So whatever value I pass into this script will tail -f the file, but only show me lines that contain the value: lgwatch expression However some of the output contains a #20 control... (8 Replies)
Discussion started by: MaindotC
8 Replies

7. UNIX for Dummies Questions & Answers

Remove part of file name with sed & mv

Ok, so I have bunch of files that are named "orange__file_name.asm" and I want to batch rename them to "file_name.asm" I know that using "ls | sed s/orange__//" will get rid of the part of the file name I do not want. But how do I combine that with the mv command to actually do it? Thanks JG (5 Replies)
Discussion started by: john galt
5 Replies

8. Shell Programming and Scripting

Awk & sed query for output

Hello, I have a file. its content are like below. mdn:87439842 imsi:23082038203 Ctime:12082010 01:20:10 mdn:9324783783 imsi:402349823322 Ctime: 12072010 01:20:10 mdn:87439842 imsi:23082038203 Ctime: 23072010 01:20:10 mdn:87439842 imsi:23082038203 Ctime:18072010 01:20:10 mdn:87439842... (3 Replies)
Discussion started by: Sanket11
3 Replies

9. UNIX for Dummies Questions & Answers

Question: Help need to remove blank line & sed: Couldn't re-allocate memory error.

I've shell script where i used the below command to take the line which contains patterns. sed -n "/$year 05:/,/$year 17:/p" trace.log | grep -f patterns.txt > output.log This was working fine for long time, but now a days this script is not working with and throwing error like sed:... (8 Replies)
Discussion started by: senthil.ak
8 Replies

10. Shell Programming and Scripting

Need to remove improperly formatted fortran output line from files, tried sed

I have been trying to remove some improperly formatted lines of output from fortran code I have been using. The problem is that I have some singularities in the math for some points that causes an incorrectly large value to be reported that exceeds the normal formating set in the code resulting in... (2 Replies)
Discussion started by: gillesc_mac
2 Replies
Login or Register to Ask a Question