Question

I have a bash script that take advantage of a local toolbox to perform an operation my question is fairly simple

I have multiple files that are the same quantities but different time steps i would like to first untar them all, and then use the toolbox to perform some manipulation but i am not sure if i am on the right track.

=============================================

The file is as follows

INPUTS

fname = a very large number or files with same name but numbering
e.g wnd20121.grb
    wnd20122.grb
      .......
    wnd2012100.grb

COMMANDS

> cdo -f nc copy fname ofile(s) 

(If this is the ofile(s)=output file how can i store it for sequent use ? Take the ofile (output file) from the command and use it / save it as input to the next, producing a new subsequent numbered output set of ofile(s)2)

>cdo merge ofile(s) ofile2

(then automatically take the ofile(s)2 and input them to the next command and so on, producing always an array of new output files with specific set name I set but different numbering for distinguishing them)

>cdo sellon ofile(s)2  ofile(s)3

------------------------------------

To make my question clearer, I would like to know the way in which I can instruct basically through a bash script the terminal to "grab" multiple files that are usually the same name but have a different numbering to make the separate their recorded time

e.g. file1 file2 ...file n

and then get multiple outputs , with every output corresponding to the number of the file it converted.

e.g. output1 output2 ...outputn

How can I set these parameters so the moment they are generated they are stored for subsequent use in the script, in later commands?

Was it helpful?

Solution

Your question isn't clear, but perhaps the following will help; it demonstrates how to use arrays as argument lists and how to parse command output into an array, line by line:

#!/usr/bin/env bash

# Create the array of input files using pathname expansion.
inFiles=(wnd*.grb)

# Pass the input-files array to another command and read its output
# - line by line - into a new array, `outFiles`.
# The example command here simply prepends 'out' to each element of the 
# input-files array and outputs each (modified) element on its own line.
# Note: The assumption is that the filenames have no embedded newlines
# (which is usually true).
IFS=$'\n' read -r -d '' -a outFiles < \
  <(printf "%s\n" "${inFiles[@]}" | sed s'/^/out-/')

# Note: If you use bash 4, you could use `readarray -t outFiles < <(...)` instead.

# Output the resulting array.
# This also demonstrates how to use an array as an argument list 
# to pass to _any_ command.
printf "%s\n" "${outFiles[@]}"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top