Replacing dates]] with (dates)]]


 
Thread Tools Search this Thread
Homework and Emergencies Emergency UNIX and Linux Support Replacing dates]] with (dates)]]
# 8  
Old 01-15-2011
I am so sorry,

I did correct it right before your posting I belief, you are correct that is the way it should be (minor correction below). This was never an issue as only a hand full of people used my site, but lately we get so much traffic that I thought it was time to do some house cleaning.. but manual is just too much work! sorry for the incorrect posting

It should be exact

[[Ashford v thornton (1818)]]

---------- Post updated at 10:50 AM ---------- Previous update was at 10:35 AM ----------

One more example

Code:
is not a false imprisonment (see: [[Bird vjones 1845]]), although it might be actionable in [[Nuisance]]. It probably is not false imprisonment if a person accepts confinement voluntarily, with a contractual agreement as to his mode of release see: [[Robinson v balmain new ferry co 1910]].

should thus be

Code:
is not a false imprisonment (see: [[Bird v jones (1845)]]), although it might be actionable in [[Nuisance]]. It probably is not false imprisonment if a person accepts confinement voluntarily, with a contractual agreement as to his mode of release see: [[Robinson v balmain new ferry co (1910)]].

# 9  
Old 01-15-2011
Here is a small crude C program which should do 98% of what you need to do if you have defined and described your problem correctly to us. The remaining 2% is where the letter 'v' is the first letter of a plaintiff or defendant.

Please compile it and use it as follows:
Code:
gcc -o change change.c
chmod 755 change
./change infile outfile

Please try it out on a copy of your data and let me know how you get on.

Code:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

char linebuf[5000];
char newlinebuf[5000];
char patternbuf[500];


char *
change_citation()
{
   static char newbuf[500];
   static char newbuf1[500];

   char foundv = 0;
   char words = 0;
   char *q = patternbuf;
   char *r = patternbuf;
   char *t = patternbuf;
   char *n;
   char w;
   char fix = 0;

#if DEBUG
   fprintf(stderr, "patternbuf: %s\n", patternbuf);
#endif

   // count spaces and parse for ' v '. Set flag if found
   q = patternbuf;
   while (*q) {
      if (*q == ' ') words++;
      if (*q == ' ' && *(q+1) == 'v' && *(q+2) == ' ') {
         foundv = 1;
      }
      q++;
   }

#if DEBUG
   fprintf(stderr, "words: %d V: %d\n", words, foundv);
#endif

   // find end of citation
   while (*t) t++;
   // fix up brackets around citation year if necessary
   n = newbuf;
   q = patternbuf;
   while (*q) {
      if (q == t - 8 && *q != '(' ) {   // need to fix
         *n++ = *q++;
         *n++ = *q++;
         t = t - 6;
         *n++ = '(';
         *n++ = *t++;
         *n++ = *t++;
         *n++ = *t++;
         *n++ = *t++;
         *n++ = ')';
         *n++ = *t++;
         *n++ = *t;
         break;
      }
      *n++ = *q++;
   }
   *n = '\0';

   if (foundv)
      return(newbuf);

   // select a word and split on v
   q = newbuf;
   n = newbuf1;
   w = 0;
   while (*q) {
      if (*q == ' ') w++;
      *n++ = *q++;
      if (fix) continue;

      if ((words == 2 && w == 1 && *q == 'v') ||
          (words == 3 && w > 1 && *q == 'v') ||
          (words >= 4 && w > 1 && *q == 'v')) {
         *n++ = *q++;
         *n++ = ' ';
         *n++ = toupper(*q++);
         fix = 1;
      }

   }
   *n = '\0';

   return (newbuf1);
}

int
main(int argc,
     char *argv[])
{
   FILE *from, *to;
   char ch;
   char *lp = linebuf;
   char *p;
   char *pp;
   char *nlp;

   if ( argc !=3) {
       printf("Usage: change <source> <destination>\n");
       exit(1);
   }

   /* open source file */
   if ((from = fopen(argv[1], "r")) == NULL) {
       printf("Cannot open source file.\n");
       exit(1);
   }

   /* open destination file */
   if ((to = fopen(argv[2], "w")) == NULL) {
       printf("Cannot open destination file.\n");
       exit(1);
   }

   /* copy the file and fix up as necessary */
   while (!feof(from)) {
      ch = fgetc(from);
      *lp++ = ch;
      if (ch == '\n') {
         *lp = '\0';

         /* got a line */
        lp = linebuf;
        nlp = newlinebuf;
        while (*lp) {

           /* check for start of pattern */
           if (*lp == '[' && *(lp+1) == '[' ) {       // start of citation
              pp = patternbuf;
              while (*lp) {
                 if (*lp == ']' && *(lp+1) == ']') {  // end of citation
                    *pp++ = *lp++;
                    *pp++ = *lp++;
                    *pp   = '\0';

                    pp = change_citation();           // parse citation and change if necessary
                    while (*pp)                       // write citation out
                      *nlp++ = *pp++;

                    break;
                 }
                 *pp++ = *lp++;
              }
           }

           *nlp++ = *lp++;
        }
        *nlp = '\0';

        /* write out line */
        nlp = newlinebuf;
        while (*nlp) fputc(*nlp++, to);
        lp = linebuf;
     }
  }

   if (fclose(from) == EOF) {
      printf("Error closing source file.\n");
      exit(1);
   }

   if (fclose(to) == EOF) {
      printf("Error closing destination file.\n");
      exit(1);
   }

   exit(0);
}

On the following test file
Code:
#
false imprisonment (see: [[Bird v Jones (1845)]]).
false imprisonment (see: [[Bird v Jones (1845)]] and [[Smith v Jones (1865)]]).
false imprisonment (see: [[Bird et al v Jones et al 1845]] and arrest (see: [[Smith v Jones (1865)]]).
false imprisonment (see: [[Bird vjones 1845]]) and also arrest (see: [[Smith vjones 1865]]).
#
false imprisonment (see: [[Bird vjones (1845)]]) and arrest (see: [[Smith vjones (1865)]]).
false imprisonment (see: [[Bird Murphy vjones (1845)]]).
false imprisonment (see: [[Bird Murphy vjones smith (1845)]]).
false imprisonment (see: [[Bird et al vjones et al (1845)]]).

it outputs
Code:
#
false imprisonment (see: [[Bird v Jones (1845)]]).
false imprisonment (see: [[Bird v Jones (1845)]] and [[Smith v Jones (1865)]]).
false imprisonment (see: [[Bird et al v Jones et al (1845)]] and arrest (see: [[Smith v Jones (1865)]]).
false imprisonment (see: [[Bird v Jones (1845)]]) and also arrest (see: [[Smith v Jones (1865)]]).
#
false imprisonment (see: [[Bird v Jones (1845)]]) and arrest (see: [[Smith v Jones (1865)]]).
false imprisonment (see: [[Bird Murphy v Jones (1845)]]).
false imprisonment (see: [[Bird Murphy v Jones smith (1845)]]).
false imprisonment (see: [[Bird et al v Jones et al (1845)]]).

This User Gave Thanks to fpmurphy For This Post:
# 10  
Old 01-15-2011
Hi,

I get the following

PHP Code:
Segmentation fault (core dumped

Last edited by lawstudent; 01-15-2011 at 10:35 PM..
# 11  
Old 01-15-2011
I copied the code I gave you from this site, complied it and ran it against the test file I also provided. It performed as expected and did not core dump.

You obviously did something different. Please tell us what you did differently and why you are getting different results such as a core dump.
# 12  
Old 01-15-2011
OK it works perfectly on the test file,
I ran it on my mysql dump, and it created the dump errors.

How can I overcome this?
# 13  
Old 01-15-2011
It means that there is something in the mysql dump file other than you described to me - probably nulls or lines longer than 5000 characters.

If you can give me a pointer to the file so I can download it, I will figure out what is going on. Otherwise there is not much that I can do.
This User Gave Thanks to fpmurphy For This Post:
# 14  
Old 01-16-2011
Hi,

Its 132mb in size, right now I am dumping it as an CSV file, and see if that makes a difference. If that does not help, could I PM you the file location of the dump?

---------- Post updated at 11:02 PM ---------- Previous update was at 10:39 PM ----------

Hi,

I tried it on the csv file and it gave me the following result,

Code:
root@server [/home/lawiki/dump]# ./change lawiki_ukwiki1.csv lawiki.csv
*** glibc detected *** ./change: free(): invalid pointer: 0x9f584000 ***
======= Backtrace: =========
/lib/libc.so.6[0x9f4875a5]
/lib/libc.so.6(cfree+0x59)[0x9f4879e9]
/lib/libc.so.6(_IO_free_backup_area+0x33)[0x9f483553]
/lib/libc.so.6(__uflow+0x5c)[0x9f483bfc]
/lib/libc.so.6(getc+0xac)[0x9f47d9ec]
./change[0x8048846]
/lib/libc.so.6(__libc_start_main+0xdc)[0x9f433e9c]
./change[0x8048451]
======= Memory map: ========
08048000-08049000 r-xp 00000000 08:05 40212539   /home/lawiki/dump/change
08049000-0804a000 rw-p 00001000 08:05 40212539   /home/lawiki/dump/change
0804a000-0807e000 rw-p 00000000 00:00 0          [heap]
9f404000-9f40f000 r-xp 00000000 08:05 41713882   /lib/libgcc_s-4.1.2-20080825.so.1
9f40f000-9f410000 rw-p 0000a000 08:05 41713882   /lib/libgcc_s-4.1.2-20080825.so.1
9f41d000-9f41e000 rw-p 00000000 00:00 0
9f41e000-9f571000 r-xp 00000000 08:05 41713695   /lib/libc-2.5.so
9f571000-9f573000 r--p 00152000 08:05 41713695   /lib/libc-2.5.so
9f573000-9f574000 rw-p 00154000 08:05 41713695   /lib/libc-2.5.so
9f574000-9f578000 rw-p 00000000 00:00 0
9f583000-9f585000 rw-p 00000000 00:00 0
9f585000-9f586000 r-xp 00000000 00:00 0          [vdso]
9f586000-9f5a1000 r-xp 00000000 08:05 41713672   /lib/ld-2.5.so
9f5a1000-9f5a2000 r--p 0001a000 08:05 41713672   /lib/ld-2.5.so
9f5a2000-9f5a3000 rw-p 0001b000 08:05 41713672   /lib/ld-2.5.so
b4671000-b4687000 rw-p 00000000 00:00 0          [stack]
Aborted (core dumped)

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Display dates between two dates

Hi All, I have 2 dates in mm/dd format. sdate=10/01 (October 01) edate=10/10 (October 10) I need the dates in between these 2 dates like below. 10/01 10/02 10/03 10/04 10/05 10/06 10/07 10/08 (1 Reply)
Discussion started by: jayadanabalan
1 Replies

2. Shell Programming and Scripting

Replacing the Dates in a file

Hello Gurus, I'm beginner in Shell scripting. I got a requirement to write a script. I have a file with below (similar) content If you can observe above content, there are many date values existed (with different dates) in a format: ddMonyyyy I have to write replace all these... (7 Replies)
Discussion started by: raghu.iv85
7 Replies

3. Shell Programming and Scripting

How to get dates between two dates?

HI, to my shell script i pass two parameters date1 and date2 is there any way to get all dates betwen these two dates? if i pass 20130714 and 20130717 i need to get below dates 20130715 20130716 is it possible. thanks (3 Replies)
Discussion started by: ulab
3 Replies

4. UNIX for Advanced & Expert Users

How to get the Missing dates between two dates in the table?

Hi Am Using Unix Ksh ... I have a Table called date select * from date ; Date 01/02/2013 06/02/2013 I need the output as Missing Date 01/02/2013 02/02/2013 03/02/2013 04/02/2013 05/02/2013 06/02/2013 (2 Replies)
Discussion started by: Venkatesh1
2 Replies

5. Shell Programming and Scripting

Generating dates between two dates

HI, i have row like this HHH100037440313438961000201001012012073110220002 N in this i have 2 dates in pos 25-32 and 33-40 , so based upon the se two dates , i need to generated records between these two values so in the above record 20100101 and 20120731 need to genearte rows like this... (4 Replies)
Discussion started by: sathishsr
4 Replies

6. UNIX for Dummies Questions & Answers

How to write the dates between 2 dates into a file

Hi All, I am trying to print the dates that falls between 2 date variables into a file. Here is the example. $BUS_DATE =20120616 $SUB_DATE=20120613 Output to file abc.txt should be : 20120613,20120614,120120615,20120616 Can you pls help me accomplish this in LINUX. Thanks... (5 Replies)
Discussion started by: dsfreddie
5 Replies

7. Programming

SQL: find if a set od dates falls in another set of dates

Don't know if it is important: Debian Linux / MySQL 5.1 I have a table: media_id int(8) group_id int(8) type_id int(8) expiration date start date cust_id int(8) num_runs int(8) preferred_time int(8) edit_date timestamp ON UPDATE CURRENT_TIMESTAMP id... (0 Replies)
Discussion started by: vertical98
0 Replies

8. Programming

Dates in C

Hello, I am working on a program in C and need to read, write and manage Dates (YYY-MM-DD HH:MM). I have made my own version of a structure to store the date data and something else. Do you recommend me to use the time.h library? In such case, is it worthwhile to have an structure containing... (1 Reply)
Discussion started by: Ister
1 Replies

9. Shell Programming and Scripting

Need script to generate all the dates in DDMMYY format between 2 dates

Hello friends, I am looking for a script or method that can display all the dates between any 2 given dates. Input: Date 1 290109 Date 2 010209 Output: 300109 310109 Please help me. Thanks. :):confused: (2 Replies)
Discussion started by: frozensmilz
2 Replies

10. Shell Programming and Scripting

Difference between two dates...

Hi All, Wish you a Happy New year... I have to find the difference between two dates, the result should be the number of days. I have seen the "datecalc" function. Its good, can I have any other alternative. Thanks in Advance Raju (4 Replies)
Discussion started by: rajus19
4 Replies
Login or Register to Ask a Question