have to retrieve the distinct values (not duplicate) from 2nd column and display


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting have to retrieve the distinct values (not duplicate) from 2nd column and display
# 8  
Old 03-10-2010
Quote:
Originally Posted by shirdi
Hi malcomex999,

Thank u soo much for your help.but when I used this command , I am getting the output only NS .can you please help me further?

But my output shouls display all distinct values in the 2nd column means

NS
LW
EA

awk '{up=toupper($2);a[up]}END{for(i in a) print i}' infile
This gives me the desired output..

Code:
awk '{up=toupper($2);a[up]}END{for(i in a) print i}' infile

But you can try also jim mcnamara suggestion which is better and shorter...

Code:
awk '!arr[$2]++ {print $2}' inputfile

# 9  
Old 03-10-2010
Hi malcomex

Thank you. This command is working for me Smilie

Code:
awk '{up=toupper($2);a[up]}END{for(i in a) print i}' infile
 
NS
LW
EA

can you also tell me a function to read these values one by one ? I mean the output should be,

Code:
proceed with NS [Y/N] ?

and it should take the input from user Y or N

if it is Y it will call a function , if it is N again should display next value from the column like

Code:
proceed with LW [Y/N]?

can you please help me?Im really worried to get it Smilie

Last edited by radoulov; 03-10-2010 at 03:34 AM.. Reason: .... code tags
# 10  
Old 03-10-2010
Code:
#!/bin/ksh
awk '{up=toupper($2);a[up]}END{for(i in a) print i}' infile | while read line
do
echo "Proceed with ${line}: Y/N:"
read ans < /dev/tty
if [[ ${ans} = "Y" ]]; then
  echo ${line}
fi
done

# 11  
Old 03-10-2010
Hi malcomex,

Thank u so much Smilie but I am getting an extra line with the output as below.can you please help? first line is coming extra here Smilie

Proceed with : Y/N

Proceed with NS: Y/N

Proceed with EA: Y/N

Proceed with LW: Y/N

Proceed with Lw: Y/N
# 12  
Old 03-10-2010
Quote:
Originally Posted by shirdi
Hi malcomex,

Thank u so much Smilie but I am getting an extra line with the output as below.can you please help? first line is coming extra here Smilie

Proceed with : Y/N

Proceed with NS: Y/N

Proceed with EA: Y/N

Proceed with LW: Y/N

Proceed with Lw: Y/N
I think you have blank lines in your file but this should solve it...

Code:
#!/bin/ksh
awk 'NF{up=toupper($2);a[up]}END{for(i in a) print i}' infile | while read line
do
echo "Proceed with ${line}: Y/N:"
read ans < /dev/tty
if [[ ${ans} = "Y" ]]; then
  echo ${line}
fi

done
# 13  
Old 03-10-2010
One more:

awk '{print $2}' test2 | sort -u
# 14  
Old 03-12-2010
I want a unix shell script to pass value to SQL stored procedure

Hi malcomex, Please help me...

I want a unix shell script to pass value to SQL stored procedure.

Below is the procedure

declare
res varchar2(10);
begin
odm_load_check('PRE_SANITY',res);
dbms_output.put_line(res);
end;

select*fromerror_log;

truncatetableerror_log;

select*fromtest;


We have to pass the value to the below procedure in the procedure from a unix script.
odm_load_check('PRE_SANITY',res);

out put should be like this when we run the script:

enter the value:
value1 #we have to input this value

and then this value1 need to be passed to odm_load_check('PRE_SANITY',res); in the above procedure.Please help me , i need it very urgent Image
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Find lines with duplicate values in a particular column

I have a file with 5 columns. I want to pull out all records where the value in column 4 is not unique. For example in the sample below, I would want it to print out all lines except for the last two. 40991764 2419 724 47182 Cand A 40992936 3591 724 47182 Cand B 40993016 3671 724 47182 Cand C... (5 Replies)
Discussion started by: kaktus
5 Replies

2. Shell Programming and Scripting

Find duplicate values in specific column and delete all the duplicate values

Dear folks I have a map file of around 54K lines and some of the values in the second column have the same value and I want to find them and delete all of the same values. I looked over duplicate commands but my case is not to keep one of the duplicate values. I want to remove all of the same... (4 Replies)
Discussion started by: sajmar
4 Replies

3. Shell Programming and Scripting

Remove duplicate values in a column(not in the file)

Hi Gurus, I have a file(weblog) as below abc|xyz|123|agentcode=sample code abcdeeess,agentcode=sample code abcdeeess,agentcode=sample code abcdeeess|agentadd=abcd stereet 23343,agentadd=abcd stereet 23343 sss|wwq|999|agentcode=sample1 code wqwdeeess,gentcode=sample1 code... (4 Replies)
Discussion started by: ratheeshjulk
4 Replies

4. Shell Programming and Scripting

Filter file to remove duplicate values in first column

Hello, I have a script that is generating a tab delimited output file. num Name PCA_A1 PCA_A2 PCA_A3 0 compound_00 -3.5054 -1.1207 -2.4372 1 compound_01 -2.2641 0.4287 -1.6120 3 compound_03 -1.3053 1.8495 ... (3 Replies)
Discussion started by: LMHmedchem
3 Replies

5. Shell Programming and Scripting

Identify duplicate values at first column in csv file

Input 1,ABCD,no 2,system,yes 3,ABCD,yes 4,XYZ,no 5,XYZ,yes 6,pc,noCode used to find duplicate with regard to 2nd column awk 'NR == 1 {p=$2; next} p == $2 { print "Line" NR "$2 is duplicated"} {p=$2}' FS="," ./input.csv Now is there a wise way to de-duplicate the entire line (remove... (4 Replies)
Discussion started by: deadyetagain
4 Replies

6. Shell Programming and Scripting

Splitting the numeric vs alpha values in a column to distinct columns

How could i take an input file and split the numeric values from the alpha values (123 vs abc) to distinc columns, and if the source is blank to keep it blank (null) in both of the new columns: So if the source file had a column like: Value: |1 | |2.3| | | |No| I would... (7 Replies)
Discussion started by: driftlogic
7 Replies

7. Shell Programming and Scripting

Get the average from column, and eliminate the duplicate values.

Dear Experts, Kindly help me please, I have a big file where there is duplicate values in col 11 till col 23, every 2 rows appers a new numbers, but in each row there is different coordinates x and y in col 57 till col 74. Please i will like to get a single value and average of the x and y... (8 Replies)
Discussion started by: jiam912
8 Replies

8. UNIX for Dummies Questions & Answers

[SOLVED] remove lines that have duplicate values in column two

Hi, I've got a file that I'd like to uniquely sort based on column 2 (values in column 2 begin with "comp"). I tried sort -t -nuk2,3 file.txtBut got: sort: multi-character tab `-nuk2,3' "man sort" did not help me out Any pointers? Input: Output: (5 Replies)
Discussion started by: pathunkathunk
5 Replies

9. UNIX for Dummies Questions & Answers

count number of distinct values in each column with awk

Hi ! input: A|B|C|D A|F|C|E A|B|I|C A|T|I|B As the title of the thread says, I would need to get: 1|3|2|4 I tried different variants of this command, but I don't manage to obtain what I need: gawk 'BEGIN{FS=OFS="|"}{for(i=1; i<=NF; i++) a++} END {for (b in a) print b}' input ... (2 Replies)
Discussion started by: beca123456
2 Replies

10. Shell Programming and Scripting

Find and replace duplicate column values in a row

I have file which as 12 columns and values like this 1,2,3,4,5 a,b,c,d,e b,c,a,e,f a,b,e,a,h if you see the first column has duplicate values, I need to identify (print it to console) the duplicate value (which is 'a') and also remove duplicate values like below. I could be in two... (5 Replies)
Discussion started by: nuthalapati
5 Replies
Login or Register to Ask a Question