1 year ago

#387070

test-img

ABiologist

Extracting file content using a for loop

I have following dummy table (called sif.csv):

1,MseI,PstI
2,AatII,PstI
3,MseI,AciI

Using a for loop, I would like to extract information from the table, where the nth iteration corresponds to the nth line:

I have tried the following but the script keeps failing:

for i in {1..$(cat sif.csv | wc -l)}; do 
sl=$(sed -n "{$i}p" sif.csv | cut -d "," -f1)
enz1=$(sed -n "{$i}p" sif.csv | cut -d "," -f2)
enz2=$(sed -n "{$i}p" sif.csv | cut -d "," -f3)
echo "$sl is $enz1 and $enz2."
done

I am grateful for any assistance.

bash

loops

shell

for-loop

command-line

0 Answers

Your Answer

Accepted video resources