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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:53:19+00:00 2026-05-26T19:53:19+00:00

Working in bash under Linux ubuntu 10 here I have Bash script that reads

  • 0

Working in bash under Linux ubuntu 10 here

I have Bash script that reads lines from gedit-created .txt file and pushes then into an array. Works as expected.

However when my input is a .txt generated from Excel it throws the error

")syntax error: invalid arithmetic operator (error token is "

echo -n $elem | od -x yields
0000000 3533 0d32
0000004

I can’t help feeling I’m almost at the solution, but it is eluding me, much to my frustration. I’d appreciate some help

Thanks

@MarcB
file from excel: (cut’n’pasted from gedit; contrary to appearance there are no blank lines in this file; rather lines alternate int, str, int, str …)
0

A?GATCGGAAGAGCGTCGTGTAGGGAAAGAGTGTAGATC
1

A?GATCGGAAGAGCACACGTCTGAACTCCAGTCACATCACGAT[AC]T

2

A?GATCGGAAGAGCACACGTCTGAACTCCAGTCACCGATGTAT[AC]T

3

A?GATCGGAAGAGCACACGTCTGAACTCCAGTCACTTAGGCAT[AC]T

4

A?GATCGGAAGAGCACACGTCTGAACTCCAGTCACTGACCAAT[AC]T

5

A?GATCGGAAGAGCACACGTCTGAACTCCAGTCACACAGTGAT[AC]T

6

A?GATCGGAAGAGCACACGTCTGAACTCCAGTCACGCCAATAT[AC]T

7

A?GATCGGAAGAGCACACGTCTGAACTCCAGTCACCAGATCAT[AC]T

8

A?GATCGGAAGAGCACACGTCTGAACTCCAGTCACACTTGAAT[AC]T

9

A?GATCGGAAGAGCACACGTCTGAACTCCAGTCACGATCAGAT[AC]T

10

A?GATCGGAAGAGCACACGTCTGAACTCCAGTCACTAGCTTAT[AC]T

rtstxt='readthrusequences.txt'

# establish readthrusequence array ---------------------------------------------
# push into sparse array the readthru adapter sequence for each TruSeq index
# use the TruSeq Index number as key to the sequence
forts=${pathsir}${rtstxt}  # FileOf ReadThruSequences
  rts=( $(cat ${forts}) )

idx=""
elem=""
isIdx=1
for elem in ${rts[@]}; do
  echo '$elem:'${elem}
# echo 'elem:' ${elem} 'before IF - isIdx:' $isIdx '- idx:' $idx
  if [[ $isIdx = 1 ]]; then 
    echo ' 1_block - $isIdx:'$isIdx' - elem:'$elem' - idx:'$idx; 
    indexseq[$elem]=0; 
    #echo "  indexseq[elem] set to ${indexseq[$elem]}"; 
    idx=$elem; 
    #echo "  idx set to elem (i.e. $idx)"; 
    isIdx=0; 
    #echo "  isIdx reset to $isIdx"; 
    #echo " " ; 
  else 
    #echo " 2_block - isIdx:$isIdx - elem:$elem - idx:$idx"; 
    indexseq[$idx]=$elem; 
    #echo "  indexseq[idx] set to ${indexseq[$idx]}"; 
    isIdx="1"; idx="0"; 
    #echo "  isIdx reset to $isIdx - idx reset to $idx";
    #echo ""; 
  fi
#  echo "keys (TruSeq index): ${!indexseq[*]}"
#  echo "vals (indexed adapter seq): ${indexseq[*]}"
done

This code pushes the file contents into an array, using the int as indices and the str and values.

The commented lines were debugs. If the first is un-commented the console yields

before IF - isIdx: 1 - idx:
 - idx:k - $isIdx:1 - elem:0
")syntax error: invalid arithmetic operator (error token is "

pointing definitely to a line end issue; but I’ve banged my head on this wall for too long & haven’t found a solution. I know there’s a simple one …

  • 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-26T19:53:20+00:00Added an answer on May 26, 2026 at 7:53 pm

    An excel generated file almost certainly uses the \r\n character pair to terminate each line. (There may be a Ctrl-Z char at the end of the file). Unix based systems expect only the \n character to terminate a line of input (and Ctrl-D (not usually) as end-of-file marker).

    Solution, either edit file to remove ^M chars (\r) at the end of each line (also check for ^Z at end of file and remove that too), OR the standard is

     dos2unix file file2 .... filen
    

    I hope this helps.

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

Sidebar

Related Questions

I have the following bash script (.sh) that's working just fine in Unix. I'd
I am working on a Bash shell script that does something like this: #!/bin/bash
I'm working on a Bash shell script that runs several Python scripts like so:
I'm working with a bash script that is currently working on a server (RHEL4).
I have bash script that I use regularly in my job to automate a
I am working on a Bash script (see below) that recursively searches through directories
I am working on a bash script that is designed to tell whether or
I am working on a bash script using sed and cut that will take
I am working on a bash script that needs to take a single line
Here's a bash script I'm working on: dir=~/path/to/$1/folder if [ -d $dir ]; then

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.