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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:21:57+00:00 2026-06-15T17:21:57+00:00

I have 100 text files which look like this: File title 4 Realization number

  • 0

I have 100 text files which look like this:

File title
4
Realization number
variable 2 name
variable 3 name
variable 4 name
1   3452  4538   325.5

The first number on the 7th line (1) is the realization number, which SHOULD relate to the file name. i.e. The first file is called file1.txt and has realization number 1 (as shown above). The second file is called file2.txt and should have realization number 2 on the 7th line. file3.txt should have realization number 3 on the 7th line, and so on…

Unfortunately every file has realization=1, where they should be incremented according to the file name.

I want to extract variables 2, 3 and 4 from the 7th line (3452, 4538 and 325.5) in each of the files and append them to a summary file called summary.txt.

I know how to extract the information from 1 file:

awk 'NR==7,NR==7{print $2, $3, $4}' file1.txt

Which, correctly gives me:

3452 4538 325.5

My first problem is that this command doesn’t seem to give the same results when run from a bash script on multiple files.

#!/bin/bash    
for ((i=1;i<=100;i++));do
    awk 'NR=7,NR==7{print $2, $3, $4}' File$((i)).txt
done

I get multiple lines being printed to the screen when I use the above script.

Secondly, I would like to output those values to the summary file along with the CORRECT preceeding realization number. i.e. I want a file that looks like this:

1  3452  4538  325.5
2  4582  6853  158.2
...
100  4865 3589  15.15

Thanks for any help!

  • 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-15T17:21:59+00:00Added an answer on June 15, 2026 at 5:21 pm

    You can simplify some things and get the result you’re after:

    #!/bin/bash    
    
    for ((i=1;i<=100;i++))
    do
        echo $i $(awk 'NR==7{print $2, $3, $4}' File$i.txt)
    done
    

    You really don’t want to assign to NR=7 (as you did) and you don’t need to repeat the NR==7,NR==7 either. You also really don’t need the $((i)) notation when $i is sufficient.

    If all the files are exactly 7 lines long, you can do it all in one awk command (instead of 100 of them):

    awk 'NR%7==0 { print ++i, $2, $3, $4}' Files*.txt
    
    • 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 looks like this : 100 50 20 90 4.07498
I have an xml file which looks like this: <section> <title> title of section
I have 100 text files which contains time series starting and ending at different
I have a hundred text files to which I would like to insert the
I have to remove duplicate strings from extremely big text file (100 Gb+) Since
Let's say I have a text file that is 100 lines long. I want
I have around 100 rows of text that I want to tokenize, which are
I have some XML files of this form: <?xml version=1.0 encoding=utf-8?> <?xml-stylesheet type=text/xsl href=biomirror.xsl?>
I know that this question might have been asked like 100 times, but, believe
I have a Java program which uses a lot of text files. The program

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.