0

Am using a bash script to read from a csv file :

#!/bin/bash
b=".html"
declare -a files=()
while read line
do
   files+=("${line}${b}")
done < all_fr.csv
echo "${files[@]}" | tr ' ' '\n'

the variable $line contains an ID and i want to add .html on every ID, i tried the code above and it give me an output like this:

.html77
.html92
.html98
.html00
.html97
.html27
.html31
.html39
.html44
.html45
.html60

My IDs are long exemple : 43567

when i do store in the list $line the output is good no problem, the problem appears when i add .html

PS: i tried to use a variable : a= $line.html but didn't work for me

A picture on my csv file from windows: csv file

  • Does your input file contain `\n` line endings, or `\r\n`? – William Pursell Jun 10 '21 at 11:33
  • @WilliamPursell \n –  Jun 10 '21 at 11:35
  • What is the picture above? You describe it as `A picture of my csv file from windows`, which strongly makes me suspect it does not have unix line endings. Show the output of `xxd all_fr.csv | head` – William Pursell Jun 10 '21 at 11:38
  • How sure are you? It totally looks like your file uses `\r\n` line endings *and* you said you are using Windows (which uses `\r\n` by default). Use `dos2unix all_fr.csv` to convert the file. – Socowi Jun 10 '21 at 11:39
  • @Socowi yeah ur right i did some search and it's \r\n excuses, about windows it's to show the file nothing more –  Jun 10 '21 at 11:41
  • @WilliamPursell the output: 00000000: 3135 3434 370d 0a31 3534 3534 0d0a 3135 15447..15454..15 00000010: 3435 370d 0a31 3534 3631 0d0a 3135 3436 457..15461..1546 00000020: 320d 0a31 3534 3633 0d0a 3135 3437 300d 2..15463..15470. 00000030: 0a31 3534 3732 0d0a 3135 3437 330d 0a31 .15472..15473..1 00000040: 3534 3734 0d0a 3135 3437 380d 0a31 3534 5474..15478..154 00000050: 3739 0d0a 3135 3438 300d 0a31 3534 3835 79..15480..15485 00000060: 0d0a 3135 3439 320d 0a31 3534 3933 0d0a ..15492..15493.. 00000070: 3135 3439 340d 0a31 3534 3935 0d0a 3135 15494..15495..15 –  Jun 10 '21 at 11:42
  • 1
    `0d0a` is `\r\n` – William Pursell Jun 10 '21 at 11:43
  • @Socowi yes it did work thank you man, could you please post your answer so i can accept it!! –  Jun 10 '21 at 11:50
  • 1
    Note that you don't really need `dos2unix`. You could also just add a `tr -d '\r'` to your pipe. – William Pursell Jun 10 '21 at 16:21

0 Answers0