remove values of a file one by one from 2nd file and then print the remaining values of 2nd file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting remove values of a file one by one from 2nd file and then print the remaining values of 2nd file
# 1  
Old 11-09-2010
remove values of a file one by one from 2nd file and then print the remaining values of 2nd file

Hi all,

I have 2 files. One contains only 1 column and other one contains 2 columns, let say 1_col.txt and 2_col.txt respectively. Here, I will try to explain with an example.

Input files :
Code:
1_col.txt          2_col.txt
a                       a    b
x                       a    c
p                       m    n
                        o    p
                        q    r
                        q    p
                        x    y

In output files, I need to remove values of 1_col.txt one by one from 2_col.txt and then just print the remaining values of 2_col.txt
output files :
Code:
output.1  output.2  output.3
m   n     a   b     a   b
o   p     a   c     a   c
q   r     m   n     m   n
q   p     o   p     q   r
x   y     q   r     x   y
          q   p

output.1 doesn't have any line containing value "a" .
output.2 doesn't have any line containing value "x".
output.3 doesn't have any line containing value "p".

In this way, the number of output files should be equal to the number of lines in 1_col.txt.

Any help would be highly appreciated,

Thanks & Regards,
Ashwani

Last edited by AshwaniSharma09; 11-09-2010 at 07:26 AM.. Reason: code tags
# 2  
Old 11-09-2010
I hope you see why we want you to use code tags, in this case to preserve the otherwise lost formatting (though bizarre here... I corrected the best the first one leaving to you to do the rest...)

All the best
# 3  
Old 11-09-2010
Code:
perl -nle '{local $/;open O, "2_col.txt";$o=<O>};$_=".*$_.*\n";$o=~s/$_//g;print $o' 1_col.txt

# 4  
Old 11-09-2010
try this,
Code:
awk 'NR==FNR{a[$1]++;next} {b[$0]++} END{for(j in a) {for (k in b) {split(k,p);if(j != p[1] && j!=p[2]) {print k > j".txt"}}}} ' 1_col.txt 2_col.txt

# 5  
Old 11-09-2010
Code:
awk 'NR==FNR{A[NR]=$1;next}{for(i in A) if($0!~A[i]) print>"output."i}' 1_col.txt 2_col.txt

# 6  
Old 11-12-2010
Thank you guys. I got my results.
@vbe - Thanks for the reminder. I will keep it in mind next time.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Taking key values from one file and extracting values from another file

Hi, I have two files with values in both. File1: cat 2 3 dog 4 5 elephant 6 7 camel 2 3 File2: ----+--gkf;ajf= ---+---- +----- cat -------=----+ 3 | 4 ----- dog ------++-- 5 | 9 ----++-- elephant | 5 | 7 ---++ camel ------ ++++_---- || 8 | 9 I want the final file as: cat 4... (1 Reply)
Discussion started by: npatwardhan
1 Replies

2. 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

3. UNIX for Dummies Questions & Answers

Reading Xml file and print the values into the text file in columnwise?

hi guys, i want help... Reding XML file and print the values into the text file using linux shell script file as per below xml file <sequence> <Filename>aldorzum.doc</Filename> <DivisionCode>US</DivisionCode> <ContentType>Template</ContentType> <ProductCode>VIMZIM</ProductCode> </sequence>... (4 Replies)
Discussion started by: sravanreddy
4 Replies

4. UNIX for Dummies Questions & Answers

Reading XML file and print the values in the text file using Linux shell script

hi guys, i want help... Reding XML file and print the values into the text file using linux shell script file as per below xml file <sequence> <Filename>aldorzum.doc</Filename> <DivisionCode>US</DivisionCode> <ContentType>Template</ContentType> <ProductCode>VIMZIM</ProductCode> </sequence>... (1 Reply)
Discussion started by: sravanreddy
1 Replies

5. Shell Programming and Scripting

Compare values in two files. For matching rows print corresponding values from File 1 in File2.

- I have two files (File 1 and File 2) and the contents of the files are mentioned below. - I am trying to compare the values of Column1 of File1 with Column1 of File2. If a match is found, print the corresponding value from Column2 of File1 in Column5 of File2. - I tried to modify and use... (10 Replies)
Discussion started by: Santoshbn
10 Replies

6. UNIX for Advanced & Expert Users

Awk to print values of second file

Hello, I have a data file with 300,000 records in it, and another file which contains only the line numbers of roughly 13,000 records in the data file which have data integrity issues. I'm trying to find a way to print the original data by line number identified in the second file. How can I do... (2 Replies)
Discussion started by: peteroc
2 Replies

7. 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

8. 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

9. Shell Programming and Scripting

How to print the lines after 2nd line from text file

Hi All, I need to print the lines after 2nd line irrespective of the number of lines in file if the file contents are like below ---------- root:!:0:0::/root:/usr/bin/ksh daemon:!:1:1::/etc: bin:!:2:2::/bin: sys:!:3:3::/usr/sys: adm:!:4:4::/var/adm: uucp:!:5:5::/usr/lib/uucp:... (6 Replies)
Discussion started by: ram1729
6 Replies
Login or Register to Ask a Question