Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8453403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:45:55+00:00 2026-06-10T11:45:55+00:00

I have been looking for a way to reformat a CSV (Pipe separator) file

  • 0

I have been looking for a way to reformat a CSV (Pipe separator) file with some if parameters, I’m pretty sure this can be done in PHP (strpos and if statements) or using XSLT but wanted to know if this is the best/easiest way to do it before I go and learn my way around a new language. here is a small example of the kind of thing I’m trying to achieve (the real file is about 25000 lines is this changes the answer?)

99407350|Math Book #13 (Random Information)|AB Collings|http:www.abc.com/ABC
497790366|English Book|Harold Herbert|http:www.abc.com/HH

Transform to this:

99407350|Math Book|#13|AB Collings|http:www.abc.com/ABC
497790366|English Book||Harold Herbert|http:www.abc.com/HH

Any advice about which direction I need to look in would be great.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T11:45:57+00:00Added an answer on June 10, 2026 at 11:45 am

    PHP provides getcsv() (PHP 5) and fgetcsv() (PHP 4 and 5) for this, so if you are working in a PHP environment, use that. See e.g. http://www.php.net/manual/en/function.fgetcsv.php

    If you do something yourself, remember to cope with “…|…” and/or \| to have | inside a field. Or test to make sure it can’t happen – e.g. check the code that exports the database to CSV if that’s what’s happening.

    Note also – on Unix / Solaris / Linux / OS X systems,
    awk -F ‘|’ ‘(NF != 9)’ yourfile.csv | wc
    will count the number of lines with other than 9 fields; if you are certain | never occurs except as a field delimiter, awk is a perfectly fine language for this too, e.g. with
    awk -F ‘|’ ‘{ gsub(/ [(].*[)]/, “”, $1); print}’ yourfile.csv

    Here, [(] matches ( in a way that works across different versions of awk, and same for [)].

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been struggling looking for an understandable way to do this. I have four
i have been looking at the API http://apidocs.mailchimp.com/api/1.3/ and i can't find a way
I have been looking for a better way to handle this issue maybe its
I have been looking for weeks for a way to do this: Screenshot http://img229.imageshack.us/img229/2430/screenshoteor.png
I have been looking for this pattern for some time but still did not
I have been looking for a way to do this all around the internet
I have been looking through trying to find some way to redirect to an
I have been looking on the net for some way to change the look
So I have been looking around for some time now on a way to
I have been looking all over for a way to do this but most

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.