We’d like to remind Forumites to please avoid political debate on the Forum.

This is to keep it a safe and useful space for MoneySaving discussions. Threads that are – or become – political in nature may be removed in line with the Forum’s rules. Thank you for your understanding.

📨 Have you signed up to the Forum's new Email Digest yet? Get a selection of trending threads sent straight to your inbox daily, weekly or monthly!

I need a person who can do php

Hi guys and girls,

I need the help of a person who can help me write a very simple php program to do some basic text file manipulation.

I have some large (ie 10,000+ lines) files that contain the format of:

Description|URL

Now what I need to do is take these files and remove the description and insert a string like the following:

[counter].html|URL

So its basically replacing the description with an incremented counter, followed by .html if you follow.

I have very little coding experience. Any help would be appreciated.

Comments

  • I can code PHP to a fairly basic standard so if nobody else with more experience than me volunteers then PM me and I'll give it a go. It sounds easy enough but I'm not promising anything!
  • Oh, one other thing.

    If you have an editor like Vi or ViM (both freeware I believe) you should be able to do this simply by opening the file with that and then using the search and replace option, it does have regex support I believe.

    Easier than writing a program to do it, assuming it is possible using Vi etc.
  • Soulistic
    Soulistic Posts: 199 Forumite
    Part of the Furniture Combo Breaker
    I agree with "ihatepasswords"... just get a good editor to do it for you. I would recommend Notepad++ as it does syntax highlighting for all different code bases, and allows you to do a quick search and replace option.
  • kally
    kally Posts: 18 Forumite
    I assume that because you're thinking of using PHP, you've got access to Linux. In which case, what you want to achieve can be done using "awk" because your require each line to have a incremental counter. Here is the awk script (store this in a file called test.awk)

    BEGIN {a=1;FS="|"}
    {print "["a++"].html|"$1;}

    Then run this from the command line as follows:

    awk -f test.awk "your input file"

    I've assumed that in your input file the "|" occurs only once, if this isn't the case then then script won't work.
  • irnbru_2
    irnbru_2 Posts: 1,603 Forumite
    kally wrote:
    I assume that because you're thinking of using PHP, you've got access to Linux.

    :confused:

    PHP runs fine on Windows.
  • DrBenway
    DrBenway Posts: 256 Forumite
    Oh, one other thing.

    If you have an editor like Vi or ViM (both freeware I believe) you should be able to do this simply by opening the file with that and then using the search and replace option, it does have regex support I believe.

    Easier than writing a program to do it, assuming it is possible using Vi etc.


    You can do it with vi

    There is a plugin called increment.vim available at vim.org by stanislav sitar (thanks) which i normally use for adding line numbers.

    I edited the plugin to add the line:

    let g:I =g:I . ".html|"

    before the return function. reloaded vim, open a copy of your file and then use this command:

    :1,$:s/.*|/\=INC(1)/g
    NURSE: "Shouldn't it be sterilized, doctor?"
    DR. BENWAY: "Very likely but there's no time."
This discussion has been closed.
Meet your Ambassadors

🚀 Getting Started

Hi new member!

Our Getting Started Guide will help you get the most out of the Forum

Categories

  • All Categories
  • 351.7K Banking & Borrowing
  • 253.4K Reduce Debt & Boost Income
  • 454K Spending & Discounts
  • 244.7K Work, Benefits & Business
  • 600.1K Mortgages, Homes & Bills
  • 177.3K Life & Family
  • 258.4K Travel & Transport
  • 1.5M Hobbies & Leisure
  • 16.2K Discuss & Feedback
  • 37.6K Read-Only Boards

Is this how you want to be seen?

We see you are using a default avatar. It takes only a few seconds to pick a picture.