Execution Problems with Remove Duplicate Info


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Execution Problems with Remove Duplicate Info
# 1  
Old 04-27-2011
Execution Problems with Remove Duplicate Info

Input file
Code:
data_1 american 100
data_1 US 1000
data_1 australia 50
data_2 american 90
data_3 singapore 4
data_3 thailand 50
.
.

Desired output result
Code:
data_1 american 100
       US 1000
       australia 50
data_2 american 90
data_3 singapore 4
       thailand 50
.
.

I only wanna print out once for those repeat info in coloumn 1.
Thanks for any command to solve it out.
# 2  
Old 04-27-2011
Code:
kent$ echo "data_1 american 100
dquote> data_1 US 1000
dquote> data_1 australia 50
dquote> data_2 american 90
dquote> data_3 singapore 4
dquote> data_3 thailand 50"|awk '{if ($1 in a) gsub(/./," ",$1);else a[$1]=1; print $0}'
data_1 american 100
       US 1000
       australia 50
data_2 american 90
data_3 singapore 4
       thailand 50

This User Gave Thanks to sk1418 For This Post:
# 3  
Old 04-27-2011
Try this.

Code:
Data: 

$ cat a2.txt
data_1 american 100
data_1 US 1000
data_1 australia 50
data_2 american 90
data_3 singapore 4
data_3 thailand 50

Script:
Code:
rm final.txt
##--get unique tags
for i in ` cat a2.txt | awk  '{print $1}'|sort -u`
do
grep $i a2.txt >temp.txt
cat temp.txt | awk '{print $1}'| sort -u > temp2.txt
cat temp.txt | awk '{print $2" "$3 }'> temp3.txt

paste temp2.txt temp3.txt >> final.txt
done
cat final.txt


Code:
Output :

$ cat final.txt
data_1  american 100
        US 1000
        australia 50
data_2  american 90
data_3  singapore 4
        thailand 50


Last edited by palanisvr; 04-27-2011 at 06:39 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Execution Problems with Solaris 8

i have problems with using solaries 8 . code and commands for extracting files from CD ? especially extracting file.jar from package and batch (1 Reply)
Discussion started by: moh_abaloo
1 Replies

2. Shell Programming and Scripting

Execution Problems with awk

Ubuntu, Bash 4.3.48 Hi, I have this input file: a1:b2:c30:g4:h12:j7 and I want this output file: a1=g4:b2=h12:c30=j7 I can do it this with this code: awk -F':' '{print $1"="$4":"$2"="$5":"$3"="$6"}' INPUT > OUTPUTIn this case I have 6 columns, I calculate manually the half number of... (6 Replies)
Discussion started by: echo manolis
6 Replies

3. UNIX for Beginners Questions & Answers

Execution problems

How to find a word in a directory which contains many files? i just want to count how many such words are present in all the files? This is the code which i tried for a single file echo "Enter the file name:" read file echo "Enter the word to search:" read word if then echo "The count... (4 Replies)
Discussion started by: Meeran Rizvi
4 Replies

4. UNIX for Dummies Questions & Answers

Execution Problems with Cron

Good evening, ive got this cron to be run: if i run this manually it doesnt work,it takes me to the prompt again /export/app/CO/opge/scr/Informe_parametros_colombia.ksh >/dev/null 2>&1 here is the code fragment: coopge@coopge: opge PRODUCCION>more... (1 Reply)
Discussion started by: alexcol
1 Replies

5. Solaris

Execution problems with Mailx

Unable to send mail using mailx command. I am using solaris 5.9 I am trying to send notification for the scheduled jobs in crob but the mailx is not working. Checked the settings in submit.cf and sendmail.cf but unable to find the solution. Error message root@sshldb # nslookup mailhost... (8 Replies)
Discussion started by: Srinathkiru
8 Replies

6. Shell Programming and Scripting

Execution Problems with if statements

Hi all, I habe a file called test.log, which contain following data : 0.0 0.1 0.1 0.1 0.1 0.2 0.3 0.3 0.4 0.4 0.6 8.7 8.8 17.2 I want to show the data which gater than 9.0 But my script not working. (4 Replies)
Discussion started by: mnmonu
4 Replies

7. Shell Programming and Scripting

Execution Problems

this my source file ************* fixed *************** Begin equipmentId : d9 processor : fox number : bhhhhhh Variable # 1: Id : 100 Type : 9 nType : s gType : 5f mType : 4 LField : England DataField : london Length ... (6 Replies)
Discussion started by: teefa
6 Replies

8. Shell Programming and Scripting

Execution Problems!!

i have been working on this for a about 12 hours today say's end of file un expected any idea's using the bourne shell and its driving me nuts worked fine in bash but prof says make it work in bourne and good luck worth 13% any help would be awesome #!/bin/sh trap "rm mnt2/source/tmp/* 2>... (1 Reply)
Discussion started by: mrhiab
1 Replies

9. Programming

execution problems with cron

how to store a date into file? and how we can access date from the file? ---------- Post updated at 06:09 AM ---------- Previous update was at 06:08 AM ---------- how we can store date in file? (1 Reply)
Discussion started by: causalmodi777
1 Replies

10. Shell Programming and Scripting

execution problems with curl

I have been getting error "curl: (7) Failed to connect to IP number 1" when using the CURL command Could someone help??? (1 Reply)
Discussion started by: infernalhell
1 Replies
Login or Register to Ask a Question