Compares not working past the 4th char


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Compares not working past the 4th char
# 1  
Old 03-16-2018
Compares not working past the 4th char

There probably is a simple explanation, and maybe I haven’t searched enough for it, or I've looked at this so long I can't see my own mistake, but here’s my issue.

My code is such
Code:
#!/bin/ksh 
awk ' 
{if ($1 == $2) {print $1,$2} }
' file1.txt

File1.txt is this
Code:
000EEB2A 000EEB2A
000EEB2A 000EEB21
000EEB2A 000EEB22
000EEB2A 000EEB23
000EEB2A 000EEB24
000EEB2D 000EEB25
000EEB2D 000EEB2D
000EEBD4 000EEB2D
000EEBD4 000EEBD4
000EEC1D 000EEBD4

The results I’d thought I would get is
Code:
000EEB2A 000EEB2A
000EEB2D 000EEB2D
000EEBD4 000EEBD4

But I get this
Code:
000EEB2A 000EEB2A
000EEB2A 000EEB21
000EEB2A 000EEB22
000EEB2A 000EEB23
000EEB2A 000EEB24
000EEB2D 000EEB25
000EEB2D 000EEB2D
000EEBD4 000EEB2D
000EEBD4 000EEBD4
000EEC1D 000EEBD4

Here is the interesting thing to me. The first four characters in both fields are the same. If I modify one line to make the first four characters different, then it will not print that line. If I change the == equal to a != not equal I will only get a line that has the first four characters different. It seems anything past the first four is not considered.

Last edited by Scrutinizer; 03-16-2018 at 05:02 PM.. Reason: code tags + removed formatting
# 2  
Old 03-16-2018
This is correct. I see the desired results

Code:
tsthbs1:/tmp> cat a
#!/bin/ksh
 
#!/bin/ksh
awk '
{if ($1 == $2) {print $1,$2} }
' file
tsthbs1:/tmp> a
000EEB2A 000EEB2A
000EEB2D 000EEB2D
000EEBD4 000EEBD4
tsthbs1:/tmp>

# 3  
Old 03-16-2018
Well at least I'm not crazy. But it may be a bug in my system. I'm running this on an IBM Mainframe in Unix System Services under zOS 2.2. Thanks
# 4  
Old 03-16-2018
maybe is the format of the file. Try:
Code:
dos2ux < file.txt | awk '$1==$2 {print $1,$2}'

or
Code:
awk '{sub("\r$", "")} $1==$2 {print $1,$2}' file.txt

# 5  
Old 03-16-2018
please provide the output of: cat -vet file using code tags.
Most likely you have ^M at the end of your lines.
If so, dos2unix file to convert.
# 6  
Old 03-16-2018
Additional characters in one field should eliminate matches, not create more. Please post the output of od -tx1c File1.txt.
# 7  
Old 03-17-2018
Perhaps the number recognition is broken?
Then a cast to a string would help
Code:
if ($1"" == $2"")

This User Gave Thanks to MadeInGermany For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Working with UTF char sqlplus

I have below SQL that I wasnt to run from a solaris machine using sqlplus select * from TABLE_NAME where regexp_like(field_value, 'Α|Β|Γ|Δ|Ε|Ζ|Η|Θ|Ι|Κ|Λ|Μ|Ν|Ξ|Ο|Π|Ρ|Σ|Τ|Υ|Φ|Χ|Ψ|Ω|α|β|γ|δ|ε|ζ|η|θ|ι|κ|λ|μ|ν|ξ|ο|π|ρ|σ|τ|υ|φ|χ|ψ|ω'); When I cat the file UTF char shows perfect however when i run... (1 Reply)
Discussion started by: varun22486
1 Replies

2. Programming

Invalid conversion from char* to char

Pointers are seeming to get the best of me and I get that error in my program. Here is the code #include <stdio.h> #include <stdlib.h> #include <string.h> #define REPORTHEADING1 " Employee Pay Hours Gross Tax Net\n" #define REPORTHEADING2 " Name ... (1 Reply)
Discussion started by: Plum
1 Replies

3. Programming

Perl 2 files compares

What do i need to do have the below perl program load 205 million record files into the hash. It currently works on smaller files, but not working on huge files. Any idea what i need to do to modify to make it work with huge files: #!/usr/bin/perl $ot1=$ARGV; $ot2=$ARGV; open(mfileot1,... (2 Replies)
Discussion started by: mrn6430
2 Replies

4. Programming

error: invalid conversion from ‘const char*’ to ‘char*’

Compiling xpp (The X Printing Panel) on SL6 (RHEL6 essentially): xpp.cxx: In constructor ‘printFiles::printFiles(int, char**, int&)’: xpp.cxx:200: error: invalid conversion from ‘const char*’ to ‘char*’ The same error with all c++ constructors - gcc 4.4.4. If anyone can throw any light on... (8 Replies)
Discussion started by: GSO
8 Replies

5. UNIX for Dummies Questions & Answers

In BIND 9.3 DNS trying to get past the 256 char limit in SPF TXT records

One way I was told to do was incase strings in quotes. But I was given this option if I can get it to work. Will this work for splitting up SPF records? I am try to make bx.example.com reference spf.eu.***, spfa.eu.***, spfb.eu.***, and spfc.eu.***. spf.eu.example.com 3600 IN TXT "v=spf1... (0 Replies)
Discussion started by: tmanx
0 Replies

6. Shell Programming and Scripting

how can i past environment variables?

i am asking to do somethings like: make use of 2 environment variables: ASS1_DATA_DIR specifies the location of the input data files ASS1_OUTPUT_DIR specifies the location of the output data files i have something like that; #set environment variables set VARIABLE1=ASS1_DATA_DIR... (5 Replies)
Discussion started by: mingming88
5 Replies

7. Programming

concat const char * with char *

hello everybody! i have aproblem! i dont know how to concatenate const char* with char const char *buffer; char *b; sprintf(b,"result.txt"); strcat(buffer,b); thanx in advance (4 Replies)
Discussion started by: nicos
4 Replies

8. Programming

Adding a single char to a char pointer.

Hello, I'm trying to write a method which will return the extension of a file given the file's name, e.g. test.txt should return txt. I'm using C so am limited to char pointers and arrays. Here is the code as I have it: char* getext(char *file) { char *extension; int i, j;... (5 Replies)
Discussion started by: pallak7
5 Replies

9. Shell Programming and Scripting

How to replace any char with newline char.

Hi, How to replace any character in a file with a newline character using sed .. Ex: To replace ',' with newline Input: abcd,efgh,ijkl,mnop Output: abcd efgh ijkl mnop Thnx in advance. Regards, Sasidhar (5 Replies)
Discussion started by: mightysam
5 Replies

10. What is on Your Mind?

Past Time

Dear UNIX Folks, I guess everyone of us like to know what sysadmin typically do during his free time. Not what he/she likes as an hobbies.. but what activities does he/she often indulge in other than facing the monitor. Maybe we can come up this a better stereo-typed for sysadmin. I... (8 Replies)
Discussion started by: izy100
8 Replies
Login or Register to Ask a Question