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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:52:07+00:00 2026-05-26T17:52:07+00:00

A program has the output set to 2 decimal place floats, one on each

  • 0

A program has the output set to 2 decimal place floats, one on each line in the file. Depending on the execution, many files can be output, each with the filename cancer.ex#, where # is the number of times the program was executed from a script.

The professor has provided an awk script as the first step to generating a 95% confidence chart using gnuplot. I’d like to convert the output to to the format

conf $1 $2 $3 var#

where # is the number from cancer.ex#

I’ve developed the following:

#!/bin/bash
Files=Output/*
String

for f in $Files 
do
    String="conf "
    cat $f | while read LINE
    do
        String="$LINE "
    done
echo $String
done

I know a number of steps are missing, as I’ve just started putting this together. My problem is executing the concatenation part, as it simply doesn’t work. There is no output, nada when executing the script above. However, if I change String="$LINE to echo $LINE, then I get all the output of the files put on the terminal.

Is there a workable appending function for variables inside a loop in bash?

  • 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-26T17:52:08+00:00Added an answer on May 26, 2026 at 5:52 pm
    #!/bin/bash
    Files=( Output/* )
    String
    
    for f in "${Files[@]}"
    do
        String="conf "
        while read LINE
        do
            String+="$LINE "
        done < "$f"
    echo $String
    done
    

    The subtle difference with < "$f" instead of piping cat $f is mainly, that the while loop would execute in a subshell due the pipe, and the variable in the for loop would not actually be updated because of the subshell.

    Note also, how, at various points I made the filename handling more robust (accepting filenames with spaces, e.g.)

    Out of the box?

    That all said, I suspect you might be done with simply

    String="conf $(cat Output/*)"
    #
    String="$(for a in Output/*; do echo "conf $(cat "$a")"; done)"
    

    Proof of concept with dummy data:

    mkdir Dummy
    for a in {a..f}; do for b in {1..3}; do echo $a $b; done > Dummy/$a; done
    for a in Dummy/*; do echo "conf " $(cat $a); done
    

    Output

    conf  a 1 a 2 a 3
    conf  b 1 b 2 b 3
    conf  c 1 c 2 c 3
    conf  d 1 d 2 d 3
    conf  e 1 e 2 e 3
    conf  f 1 f 2 f 3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My program has to read files that use various encodings. They may be ANSI,
My program has two threads: Main execution thread that handles user input and queues
My program has one dialog and two sockets. Both sockets are derived from CAsyncSocket,
I have a long running program, my_prog that has some output that I want
A user of my program has reported problems reading a settings file written by
My program has the following class definition: public sealed class Subscriber { private subscription;
If a program has literally just deserialized an object (doesn't really matter how, but
The data model in my program has a number of discrete states, but I
A portion of our research group's program has auxiliary functionality provided by ctemplate library.
What do I need to do to save an image my program has generated

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.