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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:46:37+00:00 2026-06-07T14:46:37+00:00

I am new to bash shell scripting and would be thankful for suggestions of

  • 0

I am new to bash shell scripting and would be thankful for suggestions of a script that can do this task. I have a file (list.cqt) with many lines. Each line has a list of fields separated by ‘/’ in the following format:
/Field1/Field2/Field3/Field4/Field5/Field6/Field7/Field8/Field9/Field10

For e.g. the contents in list.cqt are:
/F11/F12/F13/F14/F15/F16/F17/F18/F19/F110
/F21/F22/F23/F24/F25/F26/F27/F28/F29/F210
…
/Fx1/Fx2/Fx3/Fx4/Fx5/Fx6/Fx7/Fx8/Fx9/Fx10

(I modifyied the names inside each field just for simplifying the problem. Only the number of fields is constant in each line. Contents in each field can be anything – numbers, characters, etc)

I need to write a script to execute the following command by reading each line from list.cqt:
command arg1 arg2 arg3 arg4 *arg5* arg6 arg7 arg8 arg9 arg10

Only arg4, arg5, arg7 and arg10 change for each line read. Rest all remain the same.
arg4 is Field4 in that line in list.cqt
arg5 is Field6 in that line in list.cqt
arg7 basically starts with -1000 for the first command and changes in increments of 100. So for the second command it will be -900 for second command, so on, and 0 for 11th command, 100 for 12th command, 200 for 13th command etc.
arg10 is same absolute value as arg7 but with opposite sign. So if arg7 is -600, arg10 is 600. If arg7 is 400, arg10 is -400.

For example, reading the first two lines from list.cqt in the above example of the file, the commands will be:
command arg1 arg2 arg3 F14 F16 arg6 -1000 arg8 arg9 1000
command arg1 arg2 arg3 F24 F26 arg6 -900 arg8 arg9 900

Thank you!

  • 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-07T14:46:39+00:00Added an answer on June 7, 2026 at 2:46 pm

    I added echo before command because it’s better to check if generated list is correct:

    arg7=-1000
    arg10=1000
    while read line
    do
      set $(echo $line | tr / ' ')
      echo command arg1 arg2 arg3 "$4" "$6" arg6 "$arg7" arg8 arg9 "$arg10"
      arg10=$((arg10-100))
      arg7=$((arg7+100))
    done < list.cqt
    

    If it is, just remove echo and run the script.

    Here you process list.cqt line by line and set parts of its line to positional arguments of shell; then you use this parts as $4 and $6. Variables arg10 and arg7 are increased/decreased each time a line from the list.cqt file is processed.

    Update

    You can also use arrays instead of positional arguments (thanks to Dennis Williamson and kojiro for the tip):

    arg7=-1000
    arg10=1000
    while IFS=/ read line
    do
      echo command arg1 arg2 arg3 "${line[4]}" "${line[6]}" arg6 "$arg7" arg8 arg9 "$arg10"
      arg10=$((arg10-100))
      arg7=$((arg7+100))
    done < list.cqt
    

    That makes the code a little bit faster and cleaner.

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

Sidebar

Related Questions

I'm trying to create a new launchagent file that will execute a shell script
I have a bash shell script that loops through all child directories (but not
I have an SVN repository. I have a shell/bash script that's designed to automatically
I'm quiet new to bash scripting, and I would like to convert recursively all
I am attempting to get output of a shell / bash script, that is
I'm new to bash shell scripting and it is my first day and first
I have an env var that's being set(PYTHONPATH) whenever I open a new Bash
I am trying to make a new command which runs a shell script that
I'm very new in shell scripting, and I encountered a problem that is quite
I have a Shell Scripts that read the Input #!/bin/bash echo Type the year

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.