compare files and remove a line from a file if first column is greater than 25


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting compare files and remove a line from a file if first column is greater than 25
# 1  
Old 02-22-2012
Question compare files and remove a line from a file if first column is greater than 25

my files are as follows
Code:
fileA sepearated by tab /t
00 lieferungen 
00 attractiop
01 done
02 forness
03 rasp
04 alwaysisng
04 funny
05 done1

fileB
Code:
funnymou120112
funnymou234470
mou3raspnhdhv
rddfgmoudone1438748

so all those record which are greater than 3 and which are not present in fileB are to be redirected to third file.
eg : as in above file four records
03 rasp
04 alwaysisng
04 funny
05 done1
are greter than 3 . so rasp is compared to in each line of fileB . as rasp is present in any line of fileB .it is not redirrected in output file .. if rasp is not present in any line of fileB then it is redirected to output file . so output file for above will look like

o/p
Code:
04 alwaysisng


i used this to get output
Code:
awk 'NR==FNR{a[$0];next}$1>3{for (k in a){if (k ~ $2)next}print}'  fileB fileA

i have one more requirement as for records of fileA as .. after all this execution if the column 1 of fileA is greater than 25 , then that record must be deleted from fileA and saved again in fileA

so if record in fileA is

26 alwaysisng

so as it is greater than 25 it should then be removed from fileA.
so fileA aftert execution should not contain records greater than 25.

many thanks in advance.
# 2  
Old 02-22-2012
Try something like..

Code:
while read c1 c2
do
  if [ "$c1" -ge 3 ]
  then 
     grep -q "$c2" FileB
     [ $? -ne 0 ] && echo $c1,$c2
  fi
done < FileA

# 3  
Old 02-22-2012
Code:
awk 'NR==FNR{a[$0];next}$1>25{next}$1>3{for (k in a){if (k ~ $2)next}print}' fileB fileA

# 4  
Old 02-25-2012
hi anchal it is not working..
# 5  
Old 02-27-2012
Quote:
Originally Posted by rajniman
hi anchal it is not working..
What is not working!? getting error? not proper output?
Please post it.
You could also try the another solution posted.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Compare 1st column from 2 file and if match print line from 1st file and append column 7 from 2nd

hi I have 2 file with more than 10 columns for both 1st file apple,0,0,0...... orange,1,2,3..... mango,2,4,5..... 2nd file apple,2,3,4,5,6,7... orange,2,3,4,5,6,8... watermerlon,2,3,4,5,6,abc... mango,5,6,7,4,6,def.... (1 Reply)
Discussion started by: tententen
1 Replies

2. UNIX for Beginners Questions & Answers

Compare first column from two csv files with greater than or equal, and less than

I have two csv files of different sizes. The output file needs to have file1 contents on top of file2 contents where file2 col1 is >= to file1 col1, and file2 col1(same value) is < file1 col1 (next value). So basically, some file2 rows will be matched to the same file1 row because it is the closet... (7 Replies)
Discussion started by: aachave1
7 Replies

3. Shell Programming and Scripting

Remove entire line from a file if 1st column matches a pattern

I have one requirement to delete all lines from a file if it matches below scenario. File contains three column. Employee Number, Employee Name and Employee ID Scenario is: delete all line if Employee Number (1st column) contains below 1. Non-numeric Employee Number 2. Employee Number that... (3 Replies)
Discussion started by: anshu ranjan
3 Replies

4. UNIX for Dummies Questions & Answers

Compare two column in file and extract complate line

No Chr Pos Qual GT_1 GT_2 1. chr1 478493 595 A/G G/G 2. chr1 879243 700 A/T T/T 3. chr2 889922 1300 C/C C/C 4. chr2 1926372 300 T/A T/A 5. chr3 237474 500 G/C C/C 6. chr3 575757 700 ... (2 Replies)
Discussion started by: mscott
2 Replies

5. Shell Programming and Scripting

Compare a common field in two files and append a column from File 1 in File2

Hi Friends, I am new to Shell Scripting and need your help in the below situation. - I have two files (File 1 and File 2) and the contents of the files are mentioned below. - "Application handle" is the common field in both the files. (NOTE :- PLEASE REFER TO THE ATTACHMENT "Compare files... (2 Replies)
Discussion started by: Santoshbn
2 Replies

6. Shell Programming and Scripting

Remove line feed from csv file column

Hi All, i have a csv file . In the 7th column i have data that has line feed in it. Requirement is to remove the line feed from the 7th column whenever it appears There are 11 columns in the file C1,C2,C3,C4,C5,C6,C7,C8,C9,C10,C11 The value in C7 contains line feed ( Alt + Enter ),... (2 Replies)
Discussion started by: r_t_1601
2 Replies

7. Shell Programming and Scripting

Remove line feed from csv file column

Hi All, My requirement is to remove line (3 Replies)
Discussion started by: r_t_1601
3 Replies

8. Shell Programming and Scripting

Compare two files and remove all the contents of one file from another

Hi, I have two files, in which the second file has exactly the same contents of the first file with some additional records. Now, if I want to remove those matching lines from file2 and print only the extra contents which the first file does not have, I could use the below unsophisticated... (3 Replies)
Discussion started by: royalibrahim
3 Replies

9. Shell Programming and Scripting

compare the column from 3 files and merge that line

I have 3 file, each of has got 80000 records. file1.txt ----------------------- ABC001;active;modify;accept; ABC002;notactive;modify;accept; ABC003;notactive;no-modify;accept; ABC004;active;modify;accept; ABC005;active;no-modify;accept; file2.txt ---------------------------... (8 Replies)
Discussion started by: ganesh_mak
8 Replies

10. UNIX for Advanced & Expert Users

how to remove line greater then 3000 characters.

I am using awk and it stops when it encounter line greater then 3000 character. Is there any command which will help me remove line greater then 3000 characters. (10 Replies)
Discussion started by: naren_14
10 Replies
Login or Register to Ask a Question