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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:21:19+00:00 2026-06-09T05:21:19+00:00

I have data in multiple text files that look like this: 1 DAEJ X

  • 0

I have data in multiple text files that look like this:

1  DAEJ             X            -3120041.6620      -3120042.0476     -0.3856      0.0014               
                    Y             4084614.2137       4084614.6871      0.4734      0.0015               
                    Z             3764026.4954       3764026.7346      0.2392      0.0014               

                    HEIGHT            116.0088           116.6419      0.6332      0.0017      0.0017    8.0
                    LATITUDE     36 23 57.946407    36 23 57.940907   -0.1699      0.0013      0.0012   57.5      0.0012   62.9
                    LONGITUDE   127 22 28.131395   127 22 28.132160    0.0190      0.0012      0.0013    2.3      0.0013

and I want to run it through a filter so that the output will look like this:

DAEJ: 36 23 57.940907, 127 22 28.132160, 116.6419

I can do it easily enough with grepWin using named capture by searching for:

(?<site>\w\w\w\w+)<filler>\r\n\r\n<filler>(?<height>\-?\d+\.\d+)<filler>(?<heightRMS>\d+\.\d+)<filler>\r\n<filler>(?<lat>\-?\ *\d+\ +\d+\ +\d+\.\d+)<filler>(?<latRMS>\d+\.\d+)<filler>\r\n<filler>(?<lon>\-?\ *\d+\ +\d+\ +\d+\.\d+)<filler>(?<lonRMS>\d+\.\d+)<filler>

and repacing with (ignore the unreferenced groups, I’ll use that in other implementations):

$+{site}: $+{lat}, $+{lon}, $+{height}

but of course, at the cost of doing it manually through a GUI. I was wondering if there’s a way to script it by piping pcregrep output to sed for text substitution? I’m aware of the pcregrep -M option to match the multiline regex pattern above, and I’ve been successful until that point, but I’m stuck with the sed end of the problem.

  • 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-09T05:21:20+00:00Added an answer on June 9, 2026 at 5:21 am

    I would be using awk to handle your text file:

    awk '$1 ~ /^[0-9]+$/ { printf "%s: ", $2 } $1 == "HEIGHT" { height = $3 } $1 == "LATITUDE" { printf "%s %s %s, ", $2, $3, $4 } $1 == "LONGITUDE" { printf "%s %s %s, %s\n", $5, $6, $7, height }' file.txt
    

    Broken out on multiple lines for readability:

    $1 ~ /^[0-9]+$/ { 
        printf "%s: ", $2
    }
    
    $1 == "HEIGHT" {
        height = $3
    }
    
    $1 == "LATITUDE" {
        printf "%s %s %s, ", $2, $3, $4
    }
    
    $1 == "LONGITUDE" {
        printf "%s %s %s, %s\n", $5, $6, $7, height
    }
    

    Results:

    DAEJ: 36 23 57.946407, 127 22 28.132160, 116.6419
    

    EDIT:

    Put the following code in a file called script.awk:

    $3 == "X" {
        printf "%s: ", $2
    }
    
    $1 == "HEIGHT" {
        height = $3
    }
    
    $1 == "LATITUDE" {
        if ($2 == "-" && $6 == "-") { printf "-%s %s %s, ", $7, $8, $9 }
        else if ($2 == "-") { printf "%s %s %s, ", $6, $7, $8 }
        else if ($5 == "-") { printf "-%s %s %s, ", $6, $7, $8 }
        else { printf "%s %s %s, ", $5, $6, $7 }
    }
    
    $1 == "LONGITUDE" {
        if ($2 == "-" && $6 == "-") { printf "-%s %s %s, %s\n", $7, $8, $9, height }
        else if ($2 == "-") { printf "%s %s %s, %s\n", $6, $7, $8, height }
        else if ($5 == "-") { printf "-%s %s %s, %s\n", $6, $7, $8, height }
        else { printf "%s %s %s, %s\n", $5, $6, $7, height }
    }
    

    Run like this:

    awk -f script.awk file.txt
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have multiple text files with logged data like this: 6/23/09 17:00 0.443 6/23/09
I have a text file that contains a data like ID Name Path IsTrue
I have an excel workbook in which there is data from multiple text files.
I have some data (text files) that is formatted in the most uneven manner
I have multiple data items, each with a value V that has multiple tags
I have multiple data entries that contain the following information: id_number name1 date name2
I have a query that transfers data from multiple slave tables into a single
I have a cube that I have build that has data across multiple servers.
I have a series of large, flat text files that I need to parse
I have a class that opens text files to grab first name, last name,

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.