help with organizing some non regular text


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help with organizing some non regular text
# 1  
Old 01-16-2012
MySQL help with organizing some non regular text

hey im trying to get the hex diffrences in two files ones called new and the other is named old i want it to phrase into my script,
heres how i need the info:
Code:
input='\x'94 #the new 1 byte hex change
offset=00000000 #the 1st offset of the difference 
patch 
unset input offset
input='\x'34 #the 2nd new 1 byte hex change
offset=00000001#the 2nd offset of the difference 
patch 
unset input offset
input='\x'03 #the 3rd new 1 byte hex change
offset=0000004C #the 3rd offset of the difference 
patch 
unset input offset

and so one till all the diffrences have been put into the script

can anybody help me?

thanks

Moderator's Comments:
Mod Comment Please use next time code tags for your code and data

Last edited by vbe; 01-16-2012 at 09:03 AM..
# 2  
Old 01-16-2012
You can do something like that :
Code:
$ cat lewis.ksh
cmp -l lewis_1.txt lewis_2.txt |
awk -v Q="'" '
function oct2dec(o      ,i,d){
  for(i=1;i<=length(o);++i){
    d=(8*d)+substr(o,i,1);
  }
  return d
}
{
    offset = $1;
    old    = $2;
    new    = $3;
    printf "input=" Q "\\x" Q "%x" "\n", oct2dec(new);
    printf "offset=%08X\n", offset;
    print  "patch\nunset input offset"
}
'
$ cat lewis_1.txt
abcdefghij
klmnopqrst
$ cat lewis_2.txt
aBcdEFghij
klMnopqrst
$ cmp -l lewis_1.txt lewis_2.txt
     2 142 102
     5 145 105
     6 146 106
    14 155 115
$ ./lewis.ksh
input='\x'42
offset=00000002
patch
unset input offset
input='\x'45
offset=00000005
patch
unset input offset
input='\x'46
offset=00000006
patch
unset input offset
input='\x'4d
offset=0000000E
patch
unset input offset
$

Note: My version of awk doesn't support octal and hexa specifications for numbers.

Jean-Pierre.
This User Gave Thanks to aigles For This Post:
# 3  
Old 01-17-2012
Thanks

Thanks heaps mandose exactly what i needed Smilie your a freaking pro!!!
# 4  
Old 01-18-2012
problem

hey iv noticed a problem, the offset is allways one too many eg if the change is at offset 00000054 it will say 00000055
# 5  
Old 01-18-2012
Code:
cmp -l lewis_1.txt lewis_2.txt |
awk -v Q="'" '
function oct2dec(o      ,i,d){
  for(i=1;i<=length(o);++i){
    d=(8*d)+substr(o,i,1);
  }
  return d
}
{
    offset = $1 - 1;
    old    = $2;
    new    = $3;
    printf "input=" Q "\\x" Q "%x" "\n", oct2dec(new);
    printf "offset=%08X\n", offset;
    print  "patch\nunset input offset"
}
'

Jean-Pierre.
This User Gave Thanks to aigles For This Post:
# 6  
Old 01-18-2012
thanks

thanks mate thats great Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Please help me in organizing the data in UNIX

I have an output file in the form Hostname Value1=abc Value2=def Value3=xyz Hostname1 Value1=abc1 Value2=def1 Value3=xyz1 Hostname2 Value1=abc2 Value2=def2 Value3=xyz2 | | | And so on….. I need to export this output into csv so then it should be in format (8 Replies)
Discussion started by: rahul2662
8 Replies

2. Shell Programming and Scripting

Organizing text file by Capital Names (capital word ' ' capital word)

Hi I have a file passwd_exmpl that contains: root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync... (5 Replies)
Discussion started by: eladage
5 Replies

3. Emergency UNIX and Linux Support

Regular expression (regex) clean up text

Hi, Server - MEDIAWIKI - MYSQL - CENTOS 5 - PHP5 I have a database import of close to a million pages into my wiki, mediawiki site, the format that were left with is not pretty, and I need to find a way to clean this up and present it nicely... I think regex is the best option as I can... (1 Reply)
Discussion started by: lawstudent
1 Replies

4. Programming

Organizing C++ Code

I have three directories CspInterp, FpnInterp and LinInterp. Each directory contains 4 .h and .ccp files describing 4 classes each CspInterp class CspFsInterp1d : public FsInterp1d class CspVsInterp1d : public VsInterp1d class CspFsInterp2d : public FsInterp2d class CspVsInterp2d : public... (10 Replies)
Discussion started by: kristinu
10 Replies

5. Shell Programming and Scripting

How can I get the matched text when using regular expression.

Hello: (exp) : match "exp",the matched text is stored in auto named arrays. How can I get the matched text ? What is the name of the auto named arrays on linux shell ? (4 Replies)
Discussion started by: 915086731
4 Replies

6. Shell Programming and Scripting

Organizing log

Hello, Following are the log of my sms application COMMAND: #tail -30 /var/log/smsd.log | grep Message_id | awk '{print $1,$2,$9}' OUTPUT: 2011-02-21 12:16:20,5, 03218975857, 2011-02-21 12:16:26,5, 03323048252, 2011-02-21 12:16:53,5, 03323048252, 2011-02-21 12:16:59,5,... (1 Reply)
Discussion started by: telnor
1 Replies

7. Shell Programming and Scripting

Organizing Files

Hi, I'm fairly new at scripting. I need to write a script that takes files from a source directory puts them in a target directory and sorts them by artist name. This is what I have so far #!/bin/bash source_dir='/home/tcindy/songs' target_dir='/home/tcindy/music' for path in... (2 Replies)
Discussion started by: tcindy
2 Replies

8. Shell Programming and Scripting

Convert Windows Metacharacters to Regular Text

Hi, all. I have a need to take a flat file FTP'd from Windows to Unix and convert it for loading into a MySQL database without manual intervention. However, some characters are "fancified" (e.g. the fancy Beginning and End double-quotes from Windows) that show up as codes using vi. I need to... (4 Replies)
Discussion started by: superdelic
4 Replies

9. Shell Programming and Scripting

Remove a block of Text at regular intervals

Hello all, I have a text files that consists of blocks of text. Each block of text represents a set of Cartesian coordinates for a molecule. Each block of text starts with a line that has a only a number, which is equal to the total number of atoms in the molecule. After this number is a line... (15 Replies)
Discussion started by: marcozd
15 Replies

10. Shell Programming and Scripting

Organizing a log

I have a bunch of log files generated from a shell script, its all of my facebook friends and if theyre logged in. Each file is a different person. It runs every 5 minutes. The log file is just the date and time, then 1 if theyre logged in or 0 if theyre not. part of one of the files is: Mon Aug... (5 Replies)
Discussion started by: killer54291
5 Replies
Login or Register to Ask a Question