remove unmatched values


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting remove unmatched values
# 1  
Old 11-16-2009
remove unmatched values

Below is my requirement :

unmatched values should get deleted from file1

file1
A-1
B-1
C-1
D-2
E-3
F-4
file2
D
C
F
output
C-1
D-2
F-4
# 2  
Old 11-16-2009
Code:
grep -f file2 file1 > newfile1

# 3  
Old 11-16-2009
Code:
awk -F"-" 'FNR==NR{a[$0];next}($1 in a)'  file2 file1

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to remove the values inside the html tags?

Hi, I have a txt file which contain this: <a href="linux">Linux</a> <a href="unix">Unix</a> <a href="oracle">Oracle</a> <a href="perl">Perl</a> I'm trying to extract the text in between these anchor tag and ignoring everything else using grep. I managed to ignore the tags but unable to... (6 Replies)
Discussion started by: KCApple
6 Replies

2. Shell Programming and Scripting

Remove duplicate values with condition

Hi Gents, Please can you help me to get the desired output . In the first column I have some duplicate records, The condition is that all need to reject the duplicate record keeping the last occurrence. But the condition is. If the last occurrence is equal to value 14 or 98 in column 3 and... (2 Replies)
Discussion started by: jiam912
2 Replies

3. Shell Programming and Scripting

To remove decimal values from the field

Hi Friends, Hi Friends, I have a file in the following format file.txt 1|jHDJ|1345.0000000|384837843|39084938 2|jkaehjk|5784.00000|jhejhwej|3398934 i want to remove the 3rd field data decimal points from all lines output.txt 1|jHDJ|1345|384837843|39084938... (5 Replies)
Discussion started by: i150371485
5 Replies

4. Shell Programming and Scripting

Remove rows with e column values

Hi All, I have a big file with 232 columns and 9 million rows, I want to delete all rows with same column values in col3 through col232. Also the output should be sorted based on first 2 columns. Here is a reduced example with 6 columns. I want to remove rows with duplicate values in col3... (9 Replies)
Discussion started by: alpesh
9 Replies

5. Shell Programming and Scripting

Remove lines in file1 with values from file2

Hello, I have two data files: file1 12345 aa bbb cccc 98765 qq www uuuu 76543 pp rrr bbbbb 34567 nn ccc sssss 87654 qq ppp rrrrr file2 98765 34567 I need to remove the lines from file1 if the first field contains a value that appears in file2: output 12345 aa bbb cccc 76543 pp... (2 Replies)
Discussion started by: palex
2 Replies

6. Shell Programming and Scripting

Remove dupe values from file

Hi All, I have a file something like ||MY|VAL1|VAL2|VAL3|VAL4||||SOME|NOT||.. ||MY|VAL1|VAL2|VAL3|VAL4||||SOME|NOT||.. ||MY|VAL1|VAL2|VAL3|VAL4||||SOME|NOT||.. ||MY|VAL1|VAL2|VAL3|VAL4||||SOME|NOT||.. ||MY|VAL1|VAL2|VAL3|VAL4||||SOME|NOT||.. ||MY|VAL12|VAL22|VAL32|VAL42||||SOME|NOT||..... (5 Replies)
Discussion started by: lokaish23
5 Replies

7. Shell Programming and Scripting

remove 1st and last last values of a key

For every specific keys i.e. 1st and 4th columns (a1 and ABC_001144992) remove 1st and last value (bold ones - 87942437 and 87952030 ) and print remaining input a1 87942437 87943147 1E ABC_001144992 a1 87945162 87945276 2E ABC_001144992 a1 87949524 87952030 3E ABC_001144992 a1... (3 Replies)
Discussion started by: repinementer
3 Replies

8. Shell Programming and Scripting

Remove matched values and their related groups

For each value in file1 it has to check in file2 and file3. If value matched it has to delete that value and related group value in file2 and file3. In this example it takes A , deletes A and take related group value 1 and deletes E-1,then checks in file3 and deletes K-1.After that it takes D... (7 Replies)
Discussion started by: kanagaraj
7 Replies

9. Shell Programming and Scripting

Remove end of values in file

leviathan:/lcl/apps/Tivoli/netcool/omnibus/bin>more pmonfile.dat entp_stdby ot1p_stdby lawp_stdby I am wonder how to remove the _stdby from all the values in this dat file using #!/bin/ksh Thanks! (4 Replies)
Discussion started by: LRoberts
4 Replies

10. Shell Programming and Scripting

Remove non numeric values from a variable

Hello all, I am working on a basic script but need a little help. Issue: I am running a SQL Query using sqlplus and a shell script. I have the output of the statement stored as variable $A. $A is set to "other text here 45678754 other text here". I need to strip all text except that numeric... (13 Replies)
Discussion started by: ownedthawte
13 Replies
Login or Register to Ask a Question