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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to reject row from one file to another depending upon some condition
# 1  
Old 02-22-2011
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
Code:
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
the reject.dat should look like below
Code:
name~address~email~ID~rejection remark
asdddddasdddddasdddddasdddddasdddddasdddddasdddddasddddd~sanghai~wer@trd.com~D34678~name is > 50
sam~london~sam@hotmail.com~~ID is Null

how can i do it in ksh.
# 2  
Old 02-22-2011
Maybe something like this : (might need some improvement, i didn't test it)

Code:
while IFS='~' read n ad ml id
do 
      if (( ${#n} > 50 )); then
            echo "$n~$ad~$ml~$id~name is >50" >>rejected.dat
      else  echo "$n~$ad~$ml~$id" >>valid.dat
      fi
      if [[ -z "$id" ]]; then
            echo "$n~$ad~$ml~$id~ID is NULL" >>rejected.dat
      else  echo "$n~$ad~$ml~$id" >>valid.dat
      fi
done <abc.dat

By the way, maybe the ~ need to be protected by a backslash.

Last edited by ctsgnb; 02-22-2011 at 03:58 PM..
# 3  
Old 02-22-2011
Code:
awk -F"~" 'BEGIN{print "name~address~email~ID~rejection remark" >>"reject.dat"}
{if(length($1)>50) print $0"~name is \> 50">>"reject.dat"}
{if(length($4)==0) print $0"~ID is Null" >>"reject.dat"}' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

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

2. Shell Programming and Scripting

Delete complete row according to condition

Gents, Please can you help me. In the range 4-24 column the values are duplicate some times and I will like to delete the fist occurrence and keep the last only. The file is not sorted and I can sorted because from column 75 to the end the file is increase by time.. I have a file like this... (10 Replies)
Discussion started by: jiam912
10 Replies

3. Shell Programming and Scripting

Search row by row from one file to another file if match is found print few colums of file 2

this is the requirement list.txt table1 table2 table3 testfile.txt name#place#data#select * from table1 name2#place2#data2#select * from table 10 innerjoin table3 name2#place2#data2#select * from table 10 output name place table1 name2 place table3 i tried using awk (7 Replies)
Discussion started by: vamsekumar
7 Replies

4. Shell Programming and Scripting

How to Split File to 2 depending on condition?

Hi , cat myfile.txt ! 3100.2.0.5 ! 3100.2.22.4 ! 3100.2.30.33 ! 3100.2.4.1 ! ! 3100.2.0.5 ! 3100.2.22.4 ! 3100.2.22.11 ! 3100.2.4.1 ! ! 3100.2.0.5 ! 3100.2.2.50 ! 3100.2.22.11 ! 3100.2.4.1 ! ! 3100.2.0.5 ! 3100.2.22.4 ! 3100.2.30.33 ! 3100.2.4.1 ! ! 3100.2.0.5 ! 3100.2.22.4 !... (6 Replies)
Discussion started by: OTNA
6 Replies

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

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

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

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

9. Shell Programming and Scripting

How to insert data befor some field in a row of data depending up on values in row

Hi I need to do some thing like "find and insert before that " in a file which contains many records. This will be clear with the following example. The original data record should be some thing like this 60119827 RTMS_LOCATION_CDR INSTANT_POSITION_QUERY 1236574686123083rtmssrv7 ... (8 Replies)
Discussion started by: aemunathan
8 Replies

10. Shell Programming and Scripting

Changing the column for a row in a text file and adding another row

Hi, I want to write a shell script which increments a particular column in a row from a text file and then adds another row below the current row with the incremented value . For Eg . if the input file has a row : abc xyz lmn 89 lm nk o p I would like the script to create something like... (9 Replies)
Discussion started by: aYankeeFan
9 Replies
Login or Register to Ask a Question