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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:19:13+00:00 2026-06-14T18:19:13+00:00

I have a text file and am trying to extract the data in the

  • 0

I have a text file and am trying to extract the data in the first row (or line) of the file, where each data is saved as a list (so each point is saved on it’s own line) in a new file.

example data.txt:

Name  Col  Samp1  Samp2  Samp3  Samp4  Samp5  Samp6
Car1  Red   49.3   43.2   54.3   52.3   12.5   76.8
Car2  Blu   56.3   12.4   85.4   67.1   24.5   32.5
and so on..

I would like a new list to look like this, and saved to a new file called samps.txt:

Samp1
Samp2
Samp3
Samp4
Samp5
Samp6

I am very new to shell scripting and could use all the help anyone can provide.

  • 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-14T18:19:14+00:00Added an answer on June 14, 2026 at 6:19 pm

    Read the first line into a variable

    read -r FIRSTLINE < filename
    

    Split the string into words

    WORDS=( $FIRSTLINE )
    

    Loop through the words and output them to a file

    for WORD in ${WORDS[@]}
    do
      echo $WORD >> outputfilename
    done
    

    In your case, you want to drop the first two column values. You can slice the array by using ${WORDS[@]:2 in your for statement. Alternative, you can test the values inside the for loop before echoing them to the file.

    • 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 that contains cached data in JSON format. I'm trying
I have text file with something like first line line nr 2 line three
i am trying to extract some specific data out of a text file using
I have a text file of full of sentences and I am trying to
I have a gzipped text file that I'm trying to read within PHP (using
I have been trying to replace a word in a text file with a
I'm trying to have my application read through a text file and look for
I am trying to implement vectorization of a text file...I have created a dictionary
I have Text file that contains data separated with a comma , . How
I'm trying to get data from file. The file first has three lines of

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.