help me how to use nawk for required output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help me how to use nawk for required output
# 1  
Old 01-18-2009
help me how to use nawk for required output

Hi all

i have 2 input files
1st file is
N1 | N2|N3|N4|N5|N6|N7|N8|N9
4041491000|245160|1|0|0|1|0|0|0
4041401505|152178|1|1|1|1|0|0|0
4041450004|014052|1|1|1|1|0|0|0
4041450005|580916|1|1|1|1|0|0|0
4041491000|230990|1|0|1|1|0|0|0
4041460001|338317|1|1|1|1|0|0|0

2nd file
N1 | N2|N3|N4|N5|N6|N7|N8|N9
4041491000|245160|1|0|0|1|0|0|0
4041401505|152178|1|1|1|1|0|0|0
4041450004|014052|1|8|1|1|0|0|0
4041450005|580916|1|8|1|1|0|0|0
4041491000|230990|1|0|1|1|0|0|0
4041460001|338317|1|1|1|1|0|0|0

I WANT TO COMPARE THESE FILE AND O/P SHOULD BE FIRST FILED AND THAT MISMATCH FIELD LIKE
N1|N4
4041450004|1
4041450004|8
--------------
N1|N4
4041450005|1
4041450005|8

Please help me to solve this problem its uegent
THANKS!Smilie
# 2  
Old 01-19-2009
This don't give you the desired output but it should give the direction to start with:

Code:
awk '{getline line < "file2"}
line != $0 {
  print "Line " NR " mismatched"
  print "file1: "$0
  print "file2: "line
}' file1

Regards
# 3  
Old 01-19-2009
but it is not working
# 4  
Old 01-19-2009
What's not working, errors, wrong output? Your respond doesn't make any sense.
As I mentioned, the solution don't give the desired output, it's left to you to adjust it to your own taste.

Regards
# 5  
Old 01-20-2009
Bug

sir it gives me error

that erroer in first line
and command is nit executed
and can u explain me meaning of each line
that how it wrks
# 6  
Old 01-21-2009
Code:
#!/usr/bin/perl
sub _hash{
	my ($file,%hash)=(@_);
	open FH,"$file";
	while(<FH>){
		chomp;
		next if $.==1;
		my @tmp=split("[|]",$_);
		$hash{$tmp[0]}->{N2}=$tmp[1];
		$hash{$tmp[0]}->{N3}=$tmp[2];
		$hash{$tmp[0]}->{N4}=$tmp[3];
		$hash{$tmp[0]}->{N5}=$tmp[4];
		$hash{$tmp[0]}->{N6}=$tmp[5];
		$hash{$tmp[0]}->{N7}=$tmp[6];
		$hash{$tmp[0]}->{N8}=$tmp[7];
		$hash{$tmp[0]}->{N9}=$tmp[8];
	}
	close FH;
	return \%hash;
}
sub _compare{
	my($ref1,$ref2)=(@_);
	my %hash1=%{$ref1};
	my %hash2=%{$ref2};
	for $key (keys %hash1){
		my %t1=%{$hash1{$key}};
		my %t2=%{$hash2{$key}};
		my (@arr,$header)=();
		for $k (sort keys %t1){
			if ($t1{$k} ne $t2{$k}){
				$header.="|".$k;
				push @arr,$k;
			}
		}
		if ($#arr != -1 ){
			print "N1",$header,"\n",$key;
			map {print "|",$t1{$_}} @arr;
			print "\n",$key;
			map {print "|",$t2{$_}} @arr;
			print "\n------------------\n";
		}
	}
}
_compare(_hash("a.txt"),_hash("b.txt"));

# 7  
Old 01-26-2009
Tools

sir it give some error like

net_script: sub: not found
net_script: syntax error at line 3: `my' unexpected

and please explain me this SCRIPT that how it worksSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Nawk command to output in var

Hi I have this command, which counts number of lines in a specific file and then prints it on screen.nawk 'NF{c++}END{print "Number of GPS coordinates in file: "c}' $filename I would like to have the output put into a variable, but can't seem to find the correct argument for it. How do I... (3 Replies)
Discussion started by: bulleteyedk
3 Replies

2. Shell Programming and Scripting

How to print and append output of nawk script in commandline and as well into a file?

Hi All, I am working on nawk script, has the small function which prints the output on the screen.Am trying to print/append the same output in a file. Basically nawk script should print the output on the console/screen and as well it should write/append the same result to a file. script :... (3 Replies)
Discussion started by: Optimus81
3 Replies

3. Shell Programming and Scripting

Problem getting the required output

I need a Korn shell script which does the folllowing:- If there is one "|" (pipe) delimited file so, the script should check the 5th field to be blank or not. if it is a blank tht entire line of the file should be redirected to another file. if the 5th field is not blank it should pass that. ... (4 Replies)
Discussion started by: Juhi Kashyap
4 Replies

4. Shell Programming and Scripting

script to mail monitoring output if required or redirect output to log file

Below script perfectly works, giving below mail output. BUT, I want to make the script mail only if there are any D-Defined/T-Transition/B-Broken State WPARs and also to copy the output generated during monitoring to a temporary log file, which gets cleaned up every week. Need suggestions. ... (4 Replies)
Discussion started by: aix_admin_007
4 Replies

5. Shell Programming and Scripting

nawk is truncating output

Legends, I have 2 files f1 and f2. when i use nawk to compare the difference(subtraction) from 4th column of the file, it truncates the output. can you please help to resolve this. subtraction is (4th col of f1 - 4th col of f2). but it gives only below lines out of 116. I want to print all... (7 Replies)
Discussion started by: sdosanjh
7 Replies

6. Shell Programming and Scripting

NAWK conversion of hexadecimal input to decimal output via printf, I am close I can feel it

I have searched and the answers I have found thus far have led me to this point, so I feel I am just about there. I am trying to convert a column of hexadecimal to decimal values so that I can filter out via grep just the data I want. I was able to pull my original 3 character hex value and... (10 Replies)
Discussion started by: PCGameGuy
10 Replies

7. Shell Programming and Scripting

perl required output

Hi, I have a string in log file from that i need to pick the username. the string is like this-- pid 2172 tid 3124: 160: 10110847: userName : pid 2172 tid 3124: 160: 10110847: userName : pid 2172 tid 3124: 160: 10110847: userName : pid 2172 tid 3124: 160: 10110847: userName : pid... (5 Replies)
Discussion started by: namishtiwari
5 Replies

8. Shell Programming and Scripting

output required

Hi I have the following output Message man amm (9196) is calling Hello & Alert man amtrr (9197) is stopped Find amfi (19198) is cancelled Engine Item aea (19203) is notified Engine Item2 aea2 ... (8 Replies)
Discussion started by: PrasannaKS
8 Replies

9. Shell Programming and Scripting

assigning nawk output to shell variable

Hello friends, I doing the follwing script , but found problem to store it to a shell variable. #! /bin/sh for temp in `find ./dat/vector/ -name '*.file'` do echo $temp nawk -v temp=$temp 'BEGIN{ split(temp, a,"\/"); print a}' done output: ./dat/vector/drf_all_002.file... (6 Replies)
Discussion started by: user_prady
6 Replies

10. Shell Programming and Scripting

Assigning nawk output to variables

I do a lot of command line scripting to capture data from files or other command output. I've checked in a number of Unix and scripting books but for the life of me I can't find out how to asign field data from nawk output into variables that I can manipulate later. For example, reading a two... (6 Replies)
Discussion started by: steveje0711
6 Replies
Login or Register to Ask a Question