Sponsored Content
Top Forums Shell Programming and Scripting Finding character mismatch position in two strings Post 302215042 by jim mcnamara on Tuesday 15th of July 2008 11:31:58 AM
Old 07-15-2008
or awk
Code:
echo 12345678 12345478 | \
awk ' BEGIN {pos=0}
    {
     max=(length($1) >= length($2))? length($1): length($2)     
     for(i=1; pos == 0 && i <= max; i++)
     {
     	 v1=substr($1, i, 1)  
     	 v2=substr($2, i, 1) 
     	 if(v1 != v2){ pos=i } 
     }     
    }
    END { if(pos) {printf("%d %d/%d\n", pos, v1, v2) }}'

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to insert strings at certain position

Hi, I need to insert strings "0000 00" at the each line within the file. The postion is 37 to 42. ex. name1 name2 0000 00 nam name 0000 00 The "0000 00" in two lines should be lined up. I don't know why it's not lined up when I posted it. Can anyone help? (14 Replies)
Discussion started by: whatisthis
14 Replies

2. Shell Programming and Scripting

Help in finding the max and min position

Hi, I have this input file called ttbitnres (which is catenated and sorted):- 8 0.4444 213 10 0.5555 342 11 0.5555 321 12 0.5555 231 13 0.4444 400 My code is at :- #!/bin/bash echo -e Version "\t" Number of Pass "\t" Number of Fail "\t" Rank Position "\t"Min "\t" Max... (1 Reply)
Discussion started by: ahjiefreak
1 Replies

3. Shell Programming and Scripting

Finding relative position in a file

Hi, I have a file like 123 aaaaaaaaa ddddddddd vvvvvvvvv 345 ssssssssssss dddddddddd fffffffffff dddd ff 567 --------- sssssssss ddddddd eeeeeeeee (4 Replies)
Discussion started by: saltysumi
4 Replies

4. UNIX for Dummies Questions & Answers

Help with finding matching position on strings

I have a DNA file like below and I am able to write a short program which finds/not an input motif, but I dont understand how I can include in the code to report which position the motif was found. Example I want to find the first or all "GAT" motifs and want the program to report which position... (12 Replies)
Discussion started by: pawannoel
12 Replies

5. Shell Programming and Scripting

Finding position of space in a variable

HI All, am trying to find the position of space in a variable, it is working for other characters other than space ulab="ulab1|ulab2" find_pos=`expr index $ulab '|'` echo $find_pos above code worked fine but below one says syntax error ulab="ulab ulab2" find_pos=`expr index $ulab ' '`... (2 Replies)
Discussion started by: ulab
2 Replies

6. Shell Programming and Scripting

Find position of character in multiple strings in a file

Greetings. I have a file with information like this: AMNDHRKEOEU?AMNDHRKEOEU?AMNDHRKEOEU?AMNDHRKEOEU? AMNDHRKEEU?AMNDHREOEU? AMNDHREU?AHRKEOEU?AMNDHRKEU?AMNDKEOEU? What I need to extract is the position, in every line, of every occurrence of '?' A desired output would be something... (6 Replies)
Discussion started by: Twinklefingers
6 Replies

7. Shell Programming and Scripting

Find character and Replace character for given position

Hi, i want find the character '-' in a file from position 284-298, if it occurs i need to replace it with 'O ' for the position in the file. How to do that using SED command. thanks in advance, Sara (9 Replies)
Discussion started by: Sara183
9 Replies

8. Shell Programming and Scripting

Finding a certain character in a filename and count the characters up to the certain character

Hello, I do have folders containing having funny strings in their names and one space. First, I do remove the funny strings and replace the space by an underscore. find . -name '* *' | while read file; do target=`echo "$file" | sed 's/... (2 Replies)
Discussion started by: tempestas
2 Replies

9. Shell Programming and Scripting

Count specific character of a file in each line and delete this character in a specific position

I will appreciate if you help me here in this script in Solaris Enviroment. Scenario: i have 2 files : 1) /tmp/TRANSACTIONS_DAILY_20180730.txt: 201807300000000004 201807300000000005 201807300000000006 201807300000000007 201807300000000008 2)... (10 Replies)
Discussion started by: teokon90
10 Replies

10. UNIX for Beginners Questions & Answers

Print strings from a particular position in each line

I am using bash in Fedora 30 From the below lines (ls -l output), how can I print whatever is between the strings 'status_' and '.log' $ ls -l | grep -i status -rw-rw-r--. 1 sysadmin sysadmin 378530 Nov 11 21:58 status_vsbm1.log -rw-rw-r--. 1 sysadmin sysadmin 428776 Nov 11 21:58... (8 Replies)
Discussion started by: kraljic
8 Replies
ldns(3) 						     Library Functions Manual							   ldns(3)

NAME
ldns_wire2rr, ldns_wire2pkt, ldns_wire2rdf, ldns_wire2dname- SYNOPSIS
#include <stdint.h> #include <stdbool.h> #include <ldns/ldns.h> ldns_status ldns_wire2rr(ldns_rr **rr, const uint8_t *wire, size_t max, size_t *pos, ldns_pkt_section section); ldns_wire2pkt(); ldns_status ldns_wire2rdf(ldns_rr *rr, const uint8_t *wire, size_t max, size_t *pos); ldns_status ldns_wire2dname(ldns_rdf **dname, const uint8_t *wire, size_t max, size_t *pos); DESCRIPTION
ldns_wire2rr() converts the data on the uint8_t bytearray (in wire format) to a DNS resource record. This function will initialize and allocate memory space for the rr structure. The length of the wiredata of this rr is added to the *pos value. rr: pointer to the structure to hold the rdata value wire: pointer to the buffer with the data max: the length of the data buffer (in bytes) pos: the position of the rr in the buffer (ie. the number of bytes from the start of the buffer) section: the section in the packet the rr is meant for Returns LDNS_STATUS_OK if everything succeeds, error otherwise ldns_wire2pkt() ldns_wire2rdf() converts the data on the uint8_t bytearray (in wire format) to DNS rdata fields, and adds them to the list of rdfs of the given rr. This function will initialize and allocate memory space for the dname structures. The length of the wiredata of these rdfs is added to the *pos value. All rdfs belonging to the RR are read; the rr should have no rdfs yet. An error is returned if the format cannot be parsed. rr: pointer to the ldns_rr structure to hold the rdata value wire: pointer to the buffer with the data max: the length of the data buffer (in bytes) pos: the position of the rdf in the buffer (ie. the number of bytes from the start of the buffer) Returns LDNS_STATUS_OK if everything succeeds, error otherwise ldns_wire2dname() converts the data on the uint8_t bytearray (in wire format) to a DNS dname rdata field. This function will initialize and allocate memory space for the dname structure. The length of the wiredata of this rdf is added to the *pos value. dname: pointer to the structure to hold the rdata value wire: pointer to the buffer with the data max: the length of the data buffer (in bytes) pos: the position of the rdf in the buffer (ie. the number of bytes from the start of the buffer) Returns LDNS_STATUS_OK if everything succeeds, error otherwise AUTHOR
The ldns team at NLnet Labs. Which consists out of Jelte Jansen and Miek Gieben. REPORTING BUGS
Please report bugs to ldns-team@nlnetlabs.nl or in our bugzilla at http://www.nlnetlabs.nl/bugs/index.html COPYRIGHT
Copyright (c) 2004 - 2006 NLnet Labs. Licensed under the BSD License. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. SEE ALSO
ldns_rr2wire, ldns_pkt2wire, ldns_rdf2wire, ldns_dname2wire. And perldoc Net::DNS, RFC1034, RFC1035, RFC4033, RFC4034 and RFC4035. REMARKS
This manpage was automaticly generated from the ldns source code by use of Doxygen and some perl. 30 May 2006 ldns(3)
All times are GMT -4. The time now is 10:20 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy