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

  • Home
  • SEARCH
  • 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 8097703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:50:37+00:00 2026-06-05T21:50:37+00:00

I have small script in bash, which is generating graphs via gnuplot. Everything works

  • 0

I have small script in bash, which is generating graphs via gnuplot.
Everything works fine until names of input files contain space(s).

Here’s what i’ve got:

INPUTFILES=("data1.txt" "data2 with spaces.txt" "data3.txt")

...

#MAXROWS is set earlier, not relevant.


for LINE in $( seq 0 $(( MAXROWS - 1 )) );do

gnuplot << EOF
reset
set terminal png
set output "out/graf_${LINE}.png"

filenames="${INPUTFILES[@]}"

set multiplot 

plot for [file in filenames] file every ::0::${LINE} using 1:2 with line title "graf_${LINE}"

unset multiplot
EOF
done

This code works, but only without spaces in names of input files.

In the example gnuplot evaluate this:

1 iteration: file=data1.txt  - CORRECT
2 iteration: file=data2  - INCORRECT
3 iteration: file=with  - INCORRECT
4 iteration: file=spaces.txt  - INCORRECT
  • 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-05T21:50:39+00:00Added an answer on June 5, 2026 at 9:50 pm

    The quick answer is that you can’t do exactly what you want to do. Gnuplot splits the string in an iteration on spaces and there’s no way around that (AFIK). Depending on what you want, there may be a “Work-around”. You can write a (recursive) function in gnuplot to replace a character string with another —

    #S,C & R stand for STRING, CHARS and REPLACEMENT to help this be a little more legible.
    replace(S,C,R)=(strstrt(S,C)) ? \
        replace( S[:strstrt(S,C)-1].R.S[strstrt(S,C)+strlen(C):] ,C,R) : S
    

    Bonus points to anyone who can figure out how to do this without recursion…

    Then your (bash) loop looks something like:

    INPUTFILES_BEFORE=("data1.txt" "data2 with spaces.txt" "data3.txt")
    INPUTFILES=()
    #C style loop to avoid changing IFS -- Sorry SO doesn't like the #...
    #This loop pre-processes files and changes spaces to '#_#'
    for (( i=0; i < ${#INPUTFILES_BEFORE[@]}; i++)); do 
        FILE=${INPUTFILES_BEFORE[${i}]}
        INPUTFILES+=( "`echo ${FILE} | sed -e 's/ /#_#/g'`" ) #replace ' ' with '#_#'
    done
    

    which preprocesses your input files to add ‘#_#’ to the filenames which have spaces in them… Finally, the “complete” script:

    ...
    
    INPUTFILES_BEFORE=("data1.txt" "data2 with spaces.txt" "data3.txt")
    INPUTFILES=()
    for (( i=0; i < ${#INPUTFILES_BEFORE[@]}; i++)); do 
        FILE=${INPUTFILES_BEFORE[${i}]}
        INPUTFILES+=( "`echo ${FILE} | sed -e 's/ /#_#/g'`" ) #replace ' ' with '#_#'
    done
    
    for LINE in $( seq 0 $(( MAXROWS - 1 )) );do
    gnuplot <<EOF
    filenames="${INPUTFILES[@]}"
    replace(S,C,R)=(strstrt(S,C)) ? \
            replace( S[:strstrt(S,C)-1].R.S[strstrt(S,C)+strlen(C):] , C ,R) : S
    #replace '#_#' with ' ' in filenames.
    plot for [file in filenames] replace(file,'#_#',' ') every ::0::${LINE} using 1:2 with line title "graf_${LINE}"
    
    EOF
    done
    

    However, I think the take-away here is that you shouldn’t use spaces in filenames 😉

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

Sidebar

Related Questions

I have written a small bash script which needs an ssh tunnel to draw
Aloha everyone, I have created a small bash shell script which I wanted to
I have a small script which im using to test PHP mail(), as below:
I have a small python script which draws some turtle graphics. When my script
I have written a small bash script called isinFile.sh for checking if the first
I have written (tried to) this small bash script for searching through a range
I have written small bash script to try to get the last x characters
I have small script that takes the value from a text input and needs
I have this small script: http://jsfiddle.net/gmAjC/ <input name=n1 value=test> <br/><span></span> <br/> <span style=background-color:red>after input</span>
I have a small bash script that greps/awk paragraph by using a keyword. But

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.