Help with uniq -D [prepend]


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with uniq -D [prepend]
# 1  
Old 09-16-2009
Data Help with uniq -D [prepend]

Hi,
I am trying to add a blank line between sets of replicate values. I have been trying to use
Code:
 
uniq -D [prepend] -f4 input.txt > output.txt

The input is like
Code:
 
V2-1.0               -1.0  5500.00    4162.00  529976.06030125.0      1997A
V2-1.0               -1.0  6000.00    4285.00  529976.06030125.0      1997A
V2-1.0               -1.0      0.00    1479.00  529776.06030124.0      1997A
V2-1.0               -1.0    60.00    1489.00  529776.06030124.0      1997A

I am hoping for

Code:
 
 
V2-1.0               -1.0  5500.00    4162.00  529976.06030125.0      1997A
V2-1.0               -1.0  6000.00    4285.00  529976.06030125.0      1997A
 
V2-1.0               -1.0      0.00    1479.00  529776.06030124.0      1997A
V2-1.0               -1.0    60.00    1489.00  529776.06030124.0      1997A

Man pages suggests either separate or prepend should do the job however I cannot manipulate either to work.

Thanks in advance
Ryan
# 2  
Old 09-16-2009
try this :
Code:
 uniq -f4 --all-repeated=prepend  yourfile



---------- Post updated at 01:54 PM ---------- Previous update was at 01:51 PM ----------

alternative solution :
Code:
awk '{if($5 != prev){print "\n"; prev = $5}}1' yourfile

# 3  
Old 09-16-2009
Thanks Thanhdat!,
The uniq command worked a treat however the AWK prints a 5 line gap between replicate sets. Ive played about with it but cannot reduce this. I am using gawk, would this make a difference?

Is there any way of adding say a string with a count in each blank line i.e line1, line2,line3 etc?

Thanks again
Ryan
# 4  
Old 09-16-2009
Something like that ?
Code:
awk 'NR==1{print "line"++c}NR>1 && $5 != prev{print "line"++c}{prev = $5}1' file

# 5  
Old 09-16-2009
Thanks Danmero! I didnt understand how c worked until now.
# 6  
Old 09-16-2009
c is the count variable, it's increased if the current line differ from the previous.
Test the command and u'll see.
Regards.
# 7  
Old 09-16-2009
If that's what you want here is the shorter version.
Code:
awk 'NR==1 || $5!=prev{print "line"++c}{prev = $5}1' file

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Prepend 0 to a field in a record

Hi All, I have a file like below. In the field 9 I am having 14,014,3,001/009 on the records. I want to convert the field to a three digit value. For example 14 should 014 , 3 should 003 11050;11001;;CREDITTRANC;5293218;NRATL;;;11095;;-1;14;3;29=0000;1.25... (5 Replies)
Discussion started by: arunkumar_mca
5 Replies

2. Shell Programming and Scripting

Add number prepend certain lines

from a(depends: ) bb(depends:lmbench ) cc(depends: ) CONFIG_DEFAULT1=y CONFIG_IOSCHED1=y CONFIG_CGROUP1=y ddd(depends: ) CONFIG_GENERIC_CPU1=y CONFIG_CRYPTO_AES_NI1=m to 1. a(depends: ) 2. bb(depends:lmbench ) 3. cc(depends: ) CONFIG_DEFAULT1=y ... (8 Replies)
Discussion started by: yanglei_fage
8 Replies

3. Shell Programming and Scripting

Prepend text, different matched 1st letters

Prepending lines with: your, the, a or an based on 1st letter match. You'll see my problem below: sed '/^p\|^f\|^c\|^d\|^l/ s/^/your /' list.txt > your.txt && sed '/^v\|^j\|^k\|^m\|^n\|^s/ s/^/the /' your.txt > the.txt && sed '/^b\|^g\|^h\|^q\|^r\|^t\|^w\|^z/ s/^/a /' the.txt > a.txt && sed... (10 Replies)
Discussion started by: p1ne
10 Replies

4. Shell Programming and Scripting

How to prepend filename to its content without a third file?

Hello, Is possibly there a way to prepend the filename to its content without a third file? The reason is to add a header to each file contents to distinguish each other when they are pasted side-by-side. sample.txt: XLOC_001 0 XLOC_002 23 XLOC_003 4 XLOC_012 6output (with the same... (4 Replies)
Discussion started by: yifangt
4 Replies

5. Shell Programming and Scripting

How to prepend spaces using sed command..?

hi all , i had the below sed command to append header at the starting of my output file .... sed -i -e '1i saikumar suresh hemanth' output.txt i want to append spaces to the Name saikumar how can i append with in this command ....? (1 Reply)
Discussion started by: hemanthsaikumar
1 Replies

6. Shell Programming and Scripting

sed prepend text ?

Hi, I have a file with email header information. I would like to change the Subject line. Subject: ** PROBLEM Host Alert: server.domainname is DOWN ** I'd like to change this line such as to look, Subject: serverID ACK Fw: ** PROBLEM Host Alert: server1.domainname is DOWN** How can I... (2 Replies)
Discussion started by: upengan78
2 Replies

7. Shell Programming and Scripting

prepend and append characters to the same line

Hi, I have a file 'tmp.dat' that contains the below data: 81763 40829 30405 80452 I want to prepend a ' character to the beginning of every line, and I want to append ', at the end of every line. Below is what I expect: '81763', '40829', '30405', '80452', Can anyone help me? ... (3 Replies)
Discussion started by: ChicagoBlues
3 Replies

8. UNIX for Dummies Questions & Answers

prepend columns to a file

I have two files. File 'a' has contents: 1|1 2|2 3|3 4|4 and file 'b' has contents: abc|def hij|klm nop|qrs tuv|wxy I would like to prepend file 'a' to file 'b' (with pipe) such that the contents of 'b' will be: 1|1|abc|def 2|2|hij|klm 3|3|nop|qrs 4|4|tuv|wxy (3 Replies)
Discussion started by: ChicagoBlues
3 Replies

9. Shell Programming and Scripting

Prepend name of directory to children folders

Hi, I am a shell scripting newbie. I am in need of a shell script that will prepend the name of the parent directory to the child directory. For example if the shell script called rename.sh is invoked with ">rename.sh /home/foobar/Simple" and the structure of the folder Simple is : Simple... (7 Replies)
Discussion started by: kalichar
7 Replies
Login or Register to Ask a Question