0

I want to extract ids from a text file and build a string for a curl request I tried this

#!/bin/bash
for ids in `cat numbers.txt`
do
    echo "hi/$ids/oo"
done
echo "ALL DONE"

But this gives me the wrong output. It prints

/oo12341
/oo56z49
/oo60272347
/oo2347
/oo12312356
hi/124556616/oo
ALL DONE

instead of:

 hi/12341/oo
 hi/56z49/oo
 hi/60272347/oo
 hi/2347/oo
 hi/12312356/oo
 hi/124556616/oo
fuwa07
  • 73
  • 6
  • 2
    The file `numbers.txt` has DOS line endings. – M. Nejat Aydin Jan 12 '23 at 19:02
  • 1
    Please paste your script at [shellcheck.net](http://www.shellcheck.net/) and try to implement the recommendations made there. – Cyrus Jan 12 '23 at 19:02
  • 2
    Quickfix: use `tr -d \\r < numbers.txt` instead of `cat numbers.txt`. Better long-term solution: Convert `numbers.txt` using `dos2unix` and fix the other problems in your script, see https://www.shellcheck.net/. – Socowi Jan 12 '23 at 19:14

0 Answers0