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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:02:49+00:00 2026-05-28T08:02:49+00:00

i have a file with 3 columns, the 2nd column is lat/long and may

  • 0

i have a file with 3 columns, the 2nd column is lat/long and may or may not have data.

2012-01-10 21:27:52.811,,ABC   -- No lat/long
2012-01-10 21:27:52.811,37.8889329,-112.1876328,XYZ  -- with lat long

Can some one help me with a sed/awk/perl to transform it to

2012-01-10 21:27:52.811,"37.8889329,-112.1876328",XYZ

In all other cases it should not add any double quotes

Thanks in advance

  • 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-28T08:02:50+00:00Added an answer on May 28, 2026 at 8:02 am

    I would probably do something like this, using awk:

    % echo '2012-01-10 21:27:52.811,,ABC   -- No lat/long
    2012-01-10 21:27:52.811,37.8889329,-112.1876328,XYZ  -- with lat long
    ' | awk -F',' -v OFS=','  '
    $2 && $3 {
        $2 = "\"" $2
        $3 = $3 "\""
    }
    
    1
    '
    2012-01-10 21:27:52.811,,ABC   -- No lat/long
    2012-01-10 21:27:52.811,"37.8889329,-112.1876328",XYZ  -- with lat long
    

    This assumes that the fields are comma-delimited on the way in and the way out.

    If the second and third fields are populated then

    • Put a " before the second field
    • Put a " after the third field

    Print all lines (1).

    There are a lot of assumptions here, so you’ll have to dig out the sed & awk book and tweak this to meet your needs.

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

Sidebar

Related Questions

I have a text file containing 5 columns of data. The first column contains
I have a .csv file containing 3 columns of data. I need to create
I have a .csv file that contains data for only certain columns in a
If I have a data file with columns of numbers like 3.14 0.42 6.66
I have a text file with five columns. First column has year(2011 to 2040),
I have a txt file with columns separated by tabs and based on that
I have a csv file with 5 columns. I want to fetch the row
I have a file which has multiple columns, whitespace separated. e.g: data1 data2 data3
i have an input csv file with columns position_Id, Asofdate, etc which has to
I have .csv file that contain 2 columns delimited with , . file.csv word1,word2

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.