#! /bin/bash
for (( l = 1 ; l <= 50; ++l )) ; do
for (( k = 1 ; k <= 1000; ++k )) ; do
sed -n '$l,$lp' $k.dat >> ~/Escritorio/$l.txt
done
done
The script is located in a folder together with 1000 dat files each one having 50 lines of text.
The dat files are called 1.dat
, 2.dat
,...., 1000.dat
My purpose is to make files l.txt
, where l.txt
has the l line of 1.dat
, the l line of 2.dat
, etc. For that, I use the sed
command to select the l file of each dat file.
But when I run the above script, the txt created have nothing inside...
Where is the mistake?
l=2; sed -n '$l,$lp' somefile
? Remember that shell variables are not expanded when inside single quotes. Also$lp
would refer to a variable calledlp
(you probably wantsed -n "${l}p"
instead)