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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:42:29+00:00 2026-05-30T18:42:29+00:00

I have a file which has contents on every line following this format (A,

  • 0

I have a file which has contents on every line following this format (A, B, C, and D represent text):

A B [C] D

E.g.:

cat Cat [noun] This animal likes to eat mice.
  • The first separator is the first occurrence of a space (” “) on a line.
  • The second separator is the first occurrence of a space followed by a square opening bracket (” [“).
  • The final separator is the first occurrence of a square closing bracket followed by a space (“] “).

I want to convert all of the content in this file to a CSV file, where @ is used in place of commas:

A@B@C@D
  • The original file contains many foreign characters in UTF-8.
  • There are no spaces or brackets within the contents of A and B.
  • C sometimes contains spaces, but no brackets inside the two given.
  • D contains anything from spaces, square brackets, etc. and the contents should remain unchanged by the conversion.

How can I convert this file to that format?

  • 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-05-30T18:42:31+00:00Added an answer on May 30, 2026 at 6:42 pm

    You need to perform char substitution. I suggest you use sed with regular expression. This is a piece of code corresponding to your example:

    sed -r 's/( |\[|\])+/@/g' file_to_modify.txt > file_for_output.txt
    

    For substituting every column in a specific way, the following form is used:

    sed -r 's/([^ ]+) ([^ ]+) \[([^]]+)] (.*$)/\1@\2@\3@\4/g' f1.txt > f2.txt
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this xml file which has text init. i.e Hi my name is
I have a text file which has a particular line something like sometext sometext
I have a file which has multiple columns, whitespace separated. e.g: data1 data2 data3
Little Background: I have csv file which has lots of rows and each row
Assume you have a file which has been committed in your Git repo. You
I'm using Python, and I have a file which has city names and information
I have a javascript file which has a function calling a server (url) to
I have a php file which has some variables like $name1, $name2... How can
i have a binary file which has 4 KB of header information and then
I have a JavaScript file which has a variable as such: var ads =

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.