Delete complete row according to condition


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Delete complete row according to condition
# 8  
Old 08-17-2014
Thanks to all appreciate your help it works fine... SmilieSmilie

---------- Post updated at 01:55 PM ---------- Previous update was at 01:06 PM ----------

Gents,
It is possible to modify the script to get the information rejected in a separate file
Code:
S  21309.00  21861.00  2               0       923928.7 1851604.8  77.3227  2105
S  21115.00  21871.00  1               0       926560.4 1847521.8  83.3227   153

I know I can get it using
Code:
grep -vFf newfile oldfile

but I would like to get it in a separate output.

Thanks
# 9  
Old 08-17-2014
Try:
Code:
awk '
FNR == NR {
	c[substr($0, 4, 21)]++
	next
}
c[substr($0, 4, 21)]-- == 1 {
	print
	next
}
{	print > "oldfile"
}' file file > newfile

# 10  
Old 08-17-2014
Thanks Don Cragun

I did somethig in my way,, but its more complicate,, it works but too much complicate
Code:
awk '{if(/^X/)print $0}' $jd"g".xps > tmpX10
awk 'FNR == NR {c[substr($0,4,12)]++;next}c[substr($0,4,12)]-- == 1' tmpX10 tmpX10 > tmpX11
awk 'FNR == NR {c[substr($0,20,19)]++;next}c[substr($0,20,19)]-- == 1' tmpX11 tmpX11 > tmpX12 
grep -vFf tmpX12 tmpX11 | awk '{print substr($0,1,38)}' > tmpX13
grep -vFf tmpX13 tmpX10 > tmpX

I will use your command it is more clear and efficient ... Thanks a lot for ur support
# 11  
Old 08-17-2014
Quote:
Originally Posted by RudiC
@Scrutinizer: nice approach! But shouldn't you include $4 as well, because requestor talked of char pos. 4 - 24 to be the key?
Ow, yes.. Best to use i=substr($0,4,21) everywhere ...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert Second Column Date Into EPOCH Time And Print Complete Row

Hello Team, I am stuck in getting the required output in the following case. Please help. My input file is aa|08/01/2016 bb|08/15/2016 I wish to convert the file into aa|epoch time bb|epoch time I am using following code: (3 Replies)
Discussion started by: angshuman
3 Replies

2. Shell Programming and Scripting

Awk, appending a number in the first column of a row with a condition

Hi everyone, I have a data file in which the data is stored in event blocks. What I would like to get is that the same file with every data row starting with the number of event block. So here is two event blocks from my file: <event> -2 -1 0 0 0 501 0.00000000000E+00 ... (2 Replies)
Discussion started by: hayreter
2 Replies

3. Shell Programming and Scripting

PHP : Highlight Certain Row within Condition

I have database "Students" and table "absen" absen 99.3% 98.8% 99.3% 99.1% 97.3% 99.0% 98.8% 98.9% 99.1% 99.3% 97.9% ... (0 Replies)
Discussion started by: radius
0 Replies

4. Shell Programming and Scripting

Parse tab delimited file, check condition and delete row

I am fairly new to programming and trying to resolve this problem. I have the file like this. CHROM POS REF ALT 10_sample.bam 11_sample.bam 12_sample.bam 13_sample.bam 14_sample.bam 15_sample.bam 16_sample.bam tg93 77 T C T T T T T tg93 79 ... (4 Replies)
Discussion started by: empyrean
4 Replies

5. Shell Programming and Scripting

Replacing the text in a row based on certain condition

Hi All, I felt tough to frame my question. Any way find my below input. (.CSV file) SNo, City 1, Chennai 2, None 3, Delhi 4,None Note that I have many rows ans also other columns beside my City column. What I need is the below output. SNo, City 1, Chennai 2, Chennai_new 3, Delhi... (2 Replies)
Discussion started by: ks_reddy
2 Replies

6. Linux

perl program to delete the complete record

Hi all, I want a perl program to delete the record and its contents from a file if there is no particular line in the record given that all records are separated by a blank line. For example: #100 abcd efgh hijk 123 klm #200 abcd efgh hijk klm So, the pattern here is 123. If... (0 Replies)
Discussion started by: kaav06
0 Replies

7. Shell Programming and Scripting

Combining multiple rows in single row based on certain condition using awk or sed

Hi, I'm using AIX(ksh shell). > cat temp.txt "a","b",0 "c",bc",0 "a1","b1",0 "cc","cb",1 "cc","b2",1 "bb","bc",2 I want the output as: "a","b","c","bc","a1","b1" "cc","cb","cc","b2" "bb","bc" I want to combine multiple lines into single line where third column is same. Is... (1 Reply)
Discussion started by: samuelray
1 Replies

8. Shell Programming and Scripting

How to reject row from one file to another depending upon some condition

Hi I have a input file say abc.dat which contains data as below name~address~email~ID john~newyork~john@gmail.com~1500D steve~sydney~steve@abc.com~3451E Now if length of name is > 50 or ID is null then the row should rejected to another file say reject.dat along with reason for rejection... (2 Replies)
Discussion started by: saurav2602
2 Replies

9. Shell Programming and Scripting

Delete first row last column

Hi All, I am having following file and I want to delete 1 row last column. Current File Content: ================ procedure test421 put_line procedure test321 test421 procedure test521 test321 procedure test621 test521 Expected File Content: =========================== procedure... (3 Replies)
Discussion started by: susau_79
3 Replies

10. UNIX for Advanced & Expert Users

Delete a word and complete line

Hi Canone please provide me solution how can achieve the result below: File1.txt $ sweet appleŁ1 scotish green $ This is a test1 $ sweet mangoŁ2 asia yellow $ This is a test 2 $ sweet apple red (there is no pound symbol here) germany green (1 Reply)
Discussion started by: Aejaz
1 Replies
Login or Register to Ask a Question