I'm looking to match an error code against a list of possible codes and get the nearest match. The code would be a 6 character hexadecimal string.
I have a file of error codes all of which have a specific first 3 characters, however, after that the last 3 characters may be specific or generic as below.
y and x can be any hex character.
I need to be able to match up to the correct code and the only way I have come up with is rather convoluted. It would involve splitting the original error code into 4 parts, 1st 3 chars then char4, char5 and char6. I would then run a while loop that would read in each error code from the file, split it into the same 4 parts and run comparisons as follows,
Do 1st 3 chars match, if so does char4 match or is it x or y, if so does char5 match or is it x or y, if do does char6 match or is it x or y. If all match then that's the line I need.
I haven't worked out all the detail of that solution but I know I can do it that way. I also know there has to be a better way of doing it.
Can anyone help?
Last edited by Scrutinizer; 03-19-2015 at 07:15 AM..
Reason: code tags
This one returns the longest match.
It first builds a hashed array s[] with all their shorter variants.
Then it tries to match the full given search, then the shorter variants.
These 2 Users Gave Thanks to MadeInGermany For This Post:
I have a file with contents as shown in file.texi
Would like to keep only the sections that have inlineifset till the empty line is reached. Finally replace the
following string with a space
@inlineifset{mrg, @opar{@bullet{}
I had written the following command but it messed my file
... (6 Replies)
I have two files. One is consisting of one line, with data separated by spaces and each number appearing only once.
The other is consisting of one column and multiple lines which can have some numbers appearing more than once.
It looks something like this:
file 1:
20 700 15 30
file2:
10... (10 Replies)
Im using the command below , but thats not the output that i want. it only prints the odd and even numbers.
awk '{if(NR%2){print $0 > "1"}else{print $0 > "2"}}'
Im hoping for something like this
file1:
Text hi this is just a test
text1 text2 text3 text4 text5 text6
Text hi... (2 Replies)
Hi experts , im new to Unix,AWK ,and im just not able to get this right.
I need to match for some patterns if it matches I need to print the next few words to it.. I have only three such conditions to match… But I need to print only those words that comes after satisfying the first condition..... (2 Replies)
Hello Guys,
I'm very new on here and require some help matching up and printing some columns using awk.
I have two text files. The first file has Longitude data in column 1 (lon.txt) and the second one (node.txt) has again another Longitude data in column 1 (not exact as the first one) + in... (7 Replies)
Hello,
let's start by giving you guys a few examples of the text:
"READ /TEXT123/ABC123"
"READ /TEXT123/ABC123/"
"READ TEXT123/ABC123"
"READ TEXT123/ABC123/"
"READ TEXT123/TEXT456/ABC123"
"READ /TEXT123/TEXT456/ABC123"
"READ /TEXT123/TEXT456/ABC123/"
TEXT and ABC can be and I... (5 Replies)
All
i am struggling to raplace some text in a line between two (closest) patterns ,
line="/home/usr/bin/:/home/usr/devuser,n1.9/bin:/home/usr/root/bin"
i want to replace "devuser,n1.9" with "NEWVAL", basically all teh text from "devuser" until nearest '/' with some new text.
i tried teh... (1 Reply)
Hi,
I'm trying to find the nearest match between two columns of numbers, e.g.
1,1
10,8
30,50
20,100
and the search could be e.g. 20,20
returning 10,8 - i.e. 20-10 = 10 and 20-8 = 12 totalling 22, and hence being the nearest match.
any ideas?
thanks a lot, (1 Reply)
Hi,
I have a file having some thousand records with the following sort of lines:
Error: Failed to get order data
Order: PO-BBBTGZE
Error: No CLI
Error: Failed to get order data
Order: PO-SBDJUZA
Order: PO-XBBIDEN
Error: No CLI
Error: Failed to get order data
Order: PO-BBDJUTQ
Order:... (2 Replies)