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

The Archive Base Latest Questions

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

I have a regular expression which I tested successfully on http://regexpal.com/ : ^(\.+?\),\d.+?,X,-99,-99,-99,-99,-99,-99,-99,(\d*),(\d*) Where

  • 0

I have a regular expression which I tested successfully on http://regexpal.com/ :

^(\".+?\"),\d.+?,"X",-99,-99,-99,-99,-99,-99,-99,(\d*),(\d*)

Where my test data looks like:

"AB101AA",10,"X",-99,-99,-99,-99,-99,-99,-99,394251,806376,179,"S00","SN9","00","QA","MH","X"
"AB101AF",10,"X",-99,-99,-99,-99,-99,-99,-99,394181,806429,179,"S00","SN9","00","QA","MH","X"
"AB101AG",10,"X",-99,-99,-99,-99,-99,-99,-99,394251,806376,179,"S00","SN9","00","QA","MH","X"
"AB101AH",10,"X",-99,-99,-99,-99,-99,-99,-99,394371,806359,179,"S00","SN9","00","QA","MH","X"
"AB101AJ",10,"X",-99,-99,-99,-99,-99,-99,-99,394171,806398,179,"S00","SN9","00","QA","MH","X"
"AB101AL",10,"X",-99,-99,-99,-99,-99,-99,-99,394331,806530,179,"S00","SN9","00","QA","MH","X"

I want to replace it with \1,\2,\3 on each line so for example line 1 would give

"AB101AA",394251,806376

How can I run this regex search & replace against all csv files in my folder in osx? I tried using sed but that complains with a syntax error (plus I’m unsure it will support this regex?). Additionaly, will the ^ (begining of line) and $ (end of line) anchors work line by line, or will they match the begin and end of the file?

UPDATE: Some good responses with cut, awk ect that get specific fields from the csv, but I’ve recently learnt I need to take the numbers from that list and chop them into 2 sub-values, so my example output from above would need to look like:

"AB101AA",3,94251,8,06376

As far as I know, I need to use a regex for this.

  • 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-23T09:42:30+00:00Added an answer on May 23, 2026 at 9:42 am
    for file in *csv; do
        cp $file "${file}.bak && \
        awk -F "," 'BEGIN OFS=","} {print $1,$11,$12}' ${file}.bak > ${file}
    done
    

    Or

    sed -i.bak 's/^\("[^"]\+"\),\d\+,"X",-99,-99,-99,-99,-99,-99,-99,\([0-9]\+\),\([0-9]\+\)/\1,\2,\3/' FILE(S)
    

    E.g:

    $ sed 's/^\("[^"]\+"\),[0-9]\+,"X",-99,-99,-99,-99,-99,-99,-99,\([0-9]\+\),\([0-9]\+\).*/\1,\2,\3/' <<EOF                                                   
    "AB101AA",10,"X",-99,-99,-99,-99,-99,-99,-99,394251,806376,179,"S00","SN9","00","QA","MH","X"       
    "AB101AF",10,"X",-99,-99,-99,-99,-99,-99,-99,394181,806429,179,"S00","SN9","00","QA","MH","X"
    "AB101AG",10,"X",-99,-99,-99,-99,-99,-99,-99,394251,806376,179,"S00","SN9","00","QA","MH","X"
    "AB101AH",10,"X",-99,-99,-99,-99,-99,-99,-99,394371,806359,179,"S00","SN9","00","QA","MH","X"
    "AB101AJ",10,"X",-99,-99,-99,-99,-99,-99,-99,394171,806398,179,"S00","SN9","00","QA","MH","X"
    "AB101AL",10,"X",-99,-99,-99,-99,-99,-99,-99,394331,806530,179,"S00","SN9","00","QA","MH","X"
    EOF   
    "AB101AA",394251,806376
    "AB101AF",394181,806429
    "AB101AG",394251,806376
    "AB101AH",394371,806359
    "AB101AJ",394171,806398
    "AB101AL",394331,806530
    $   
    

    HTH

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

Sidebar

Related Questions

I have a simple regular expression which looks something like ([a-z]*)( +[a-z]=[0-9])* and it
I have a regular expression which looks like this: ^(+dd)?(?(?<=+dd)((| )(0)(| )| |)|(0))(8|ddd?)[-/ ]?dd(
I have a regular expression which looks something like this: (\bee[0-9]{9}in\b)|(\bee[0-9]{9}[a-zA-Z]{2}\b) Now if the
I have a regular expression which accept time in a specific format like the
I would like to have a regular expression which clears an HTML field when
I have a string like this ch:keyword ch:test ch:some_text I need a regular expression
I have a regular expression which pulls name value pairs ([^=;]*)=([^;]*) Data Source=server;Initial Database=myDB;foo=bar;
I have a regular expression which matches a date format like : 26 August
I have the following regular expression: [0-9]{8}.*\n.*\n.*\n.*\n.* Which I have tested in Expresso against
I would like to have a regular expression which returns only the numbers and

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.