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 8244505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:52:26+00:00 2026-06-07T21:52:26+00:00

I have a pipe-delimited datafile that I want to load into Mysql via LOAD

  • 0

I have a pipe-delimited datafile that I want to load into Mysql via LOAD DATA INFILE.

Something like:

a|||d|e
x|y|z|0|1
...

I want replace an empty field with \N so that the data is recognized as a NULL value.

doing

sed ‘s/||/|\\N|/g’

almost works, but not quite – in that first data line, the second pipe is eaten up by sed so that the second contiguous empty field isn’t parsed!!!

My hacky work-around is to pipe the result of the first sed to do another identical search and replace a second time to get rid of those contiguous empty fields.

My question is, what is a more elegant way to get around this problem in sed (preferably in one pass)?

TIA.

Additional Note

If you plan to process your data file with sed, please also watch out for end of line cases like this:

h|i|j|k|

You will need to pipe to

sed ‘s/|$/|\\N/g’

to handle those end-of-line cases.

Also, if you are going from DOS to UNIX systems, you may want to erase ‘\r’ from your data file using sed search-and-replace.

I recommend that you account for all warnings from Mysql when using LOAD DATA INFILE – they will help you catch the evil cases.

  • 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-07T21:52:28+00:00Added an answer on June 7, 2026 at 9:52 pm

    You can use the repeat (t) command:

    echo 'a|||d|e' | sed ':repeat; s/||/|\N|/g; t repeat'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a List of String objects that are pipe delimited. something like this:
I have a Perl script inserting data into Postgres according to a pipe delimited
I have a pipe delimited string like this: blah|blah|blah|blah|blah|blah|blah|blah|blah|oldDate|blah|blah| I would like replace the
If I have a string of pipe-delimited data: 123456|abcd|||65464|hgfhgf How can I replace any
If I have 2 pipe delimited files containing bookmark data, for example. How can
I have a stored procedure that takes a string of a pipe delimited array
I have a pipe delimited file with some NULL date fields. I load this
I have a flat file that is pipe delimited and an database table. I
I'm creating a BCP IN process to load a pipe delimited file into a
I have a bunch of data in pipe-delimited format, where odd entries are index

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.