Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

replace (regular expressions) question

  • 09-11-2005 8:45am
    #1
    Registered Users, Registered Users 2 Posts: 648 ✭✭✭


    hi

    i have a massive csv file in this format :

    'age , (Jap.) Deep-fried. '

    (spaces included, quotes not, see file attched)
    i would like to change this to :

    'age;(Jap.) Deep-fried.'


    Does anyone know how i would do so (i want to remove the spaces also!)
    Tnx


Comments

  • Registered Users, Registered Users 2 Posts: 68,190 ✭✭✭✭seamus


    In php, a preg_replace would work with this regular expression:
    /\s+,\s+/

    That's assuming that all lines fit this format?


  • Registered Users, Registered Users 2 Posts: 648 ✭✭✭ChicoMendez


    seamus wrote:
    In php, a preg_replace would work with this regular expression:
    /\s+,\s+/

    That's assuming that all lines fit this format?

    tnx .. anyway of doing it in notepad,dreamweaver or the like as i need to do a few thousand of them in one command....


  • Registered Users, Registered Users 2 Posts: 2,188 ✭✭✭Serbian


    tnx .. anyway of doing it in notepad,dreamweaver or the like as i need to do a few thousand of them in one command....

    Dreamweaver supports Find and Replace with Regular Expressions.

    replace.gif


  • Registered Users, Registered Users 2 Posts: 68,190 ✭✭✭✭seamus


    I've gotten some mixed results with Dreamweaver. Try it on a copy of the file first.


  • Registered Users, Registered Users 2 Posts: 648 ✭✭✭ChicoMendez


    seamus wrote:
    I've gotten some mixed results with Dreamweaver. Try it on a copy of the file first.

    ya thats my issue really . DW - does nothing fo rthe command you gave me above

    /\s+,\s+/ :(


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 2,188 ✭✭✭Serbian


    You could try TextPad. It also supports Find and Replace via RegEx and is a very solid editor to boot.


  • Registered Users, Registered Users 2 Posts: 68,190 ✭✭✭✭seamus


    ya thats my issue really . DW - does nothing fo rthe command you gave me above

    /\s+,\s+/ :(
    Nah, that's a PHP regular expression. DW's regexp is similar though. Remove the forward slashes at the start and end of what I gave you and try it.


  • Registered Users, Registered Users 2 Posts: 648 ✭✭✭ChicoMendez


    i may as well juts to it in php

    i have no problem using a preg_replace

    but how would i read in my current csv file and run through it line by line?


    (i can then do the preg_replace and print the result on the screen and copy it into a new csv!)

    Tnx


  • Registered Users, Registered Users 2 Posts: 68,190 ✭✭✭✭seamus


    www.php.net is your friend.

    Search for the fopen() function, then have a look at the submitted code examples under the function.


  • Registered Users, Registered Users 2 Posts: 6,602 ✭✭✭daymobrew


    Using sed (Stream EDitor), a Unix command line utility, you could do it like:
    sed -e 's/ *, */,/g' -e 's/ *$//' replace.txt >new.txt
    
    The part removes spaces on either side of the comma, the second one removing any trailing spaces at the end of the line.

    It didn't work on the file you attached because it appears to be in Unicode.

    PM if anyone needs an explanation about what is going on in the command.


  • Advertisement
Advertisement