![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Validating XSL sheet data in Unix Data file | ravijunghare | UNIX for Dummies Questions & Answers | 1 | 11-07-2008 09:32 AM |
| extract lines based on few conditions | prvnrk | Shell Programming and Scripting | 4 | 10-17-2008 05:24 AM |
| validating a file or directory | new2Linux | Shell Programming and Scripting | 3 | 06-27-2008 12:44 AM |
| Extracting data from text file based on configuration set in config file | suparnbector | Shell Programming and Scripting | 3 | 08-10-2007 02:25 AM |
| Validating inputs from a file | sendhilmani123 | Shell Programming and Scripting | 1 | 05-10-2006 05:49 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
validating a file based on conditions
i have a file in unix in which the records are like this
aaa 123 233 aaa 234 222 aaa 242 222 bbb 122 111 bbb 122 123 ccc 124 222 In the output i want only the below records aaa ccc The validation logic is 1st column and 2nd column need to be considered if both columns values are not same and 1st column values are same then the record in 1st column need to be picked up in the records if the first and second column matches then those records need to be dropped plz. let me know how to do this validation |
|
||||
|
validating a input file in unix
hi,
thanks for the response actually in my message if there are 3 records like aaa 123 233 aaa 234 222 aaa 242 222 then only ONE aaa need to be printed but in the output it is showing all the 3 values Actually in my input file it will contain nearly 10 fields each separated by pipe symbol For that thing whether this solution will work (by replacing k[$1,$2]++ with all the fields like $3...) or i have to use another approach I have to consider the first 2 fields for validation remaining fields i can leave as it is expecting your reply thanks |
|
||||
|
hi, you may try below perl script
Code:
#! /usr/bin/perl
open FH,"<a.txt";
while(<FH>){
my @tmp=split(" ",$_);
if(! exists $hash{$tmp[0]}){
$hash{$tmp[0]}=$tmp[1]." " ;
next;
}
if((exists $hash{$tmp[0]}) && ($hash{$tmp[0]} ne 'DUP')){
$hash{$tmp[0]}=($hash{$tmp[0]} =~ m/$tmp[1] /)?'DUP':$hash{$tmp[0]}.$tmp[1]." ";
}
}
close FH;
print join "\n", grep {$hash{$_} ne 'DUP' } keys %hash;
|
|
||||
|
hi,
I have to use shell script please suggest some logic in shell script itself i haven't used perl script thanks |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|