I have a file with 2 columns and I want to use the values ββfrom the second column to set the range in the cut command to select a range of characters from another file. The range I want is the character at the position of the value in the second column plus the next 10 characters. I will give an example after a while.
My files are as follows:
A file with 2 columns and no empty lines between the lines ( file1.txt ):
NAME1 10 NAME2 25 NAME3 48 NAME4 66
The file I want to extract a range of variable characters (only one very long line without spaces and bold) ( file2.txt ):
GATCGAGCGG GATTCTTTTT TTTTA GGCGAGTCAG CTAGCATCAGCTA CGAGAGGCGA GGGCGGGC TATCACGACT ACGACTACGACTACAGCATCAGCATCAGCGCACTAGAGCGAGGCTAGCTAGCTACGACTACGATCAGCATCGCACATCGACTACGATCAGCATCAGCTACGCATCGAAGAGAGAGC
... or, more literally (for copy / paste for verification):
GATCGAGCGGGATTCTTTTTTTTTAGGCGAGTCAGCTAGCATCAGCTACGAGAGGCGAGGGCGGGCTATCACGACTACGACTACGACTACAGCATCAGCATCAGCGCACTAGAGCGAGGCTAGCTAGCTACGACTACGATCAGCATCGCACATCGACTACGATCAGCATCAGCTACGCATCGAAGAGAGAGC
Desired result file, one sequence per line ( result.txt ):
GATTCTTTTT GGCGAGTCAG CGAGAGGCGA TATCACGACT
As a result, the file will have characters from 10-20, 25-35, 48-58 and 66-76, each range in a new line. Thus, it will always maintain a range of 10, but at different start points and those start points are set to the values ββin the second column from the first file.
I tried the command:
for i in $(awk '{print $2}' file1.txt); do p1=$i; p2=`expr "$1" + 10` cut -c$p1-$2 file2.txt > result.txt; done
I do not receive any exit or error message.
I also tried:
while read line; do set $line p2=`expr "$2" + 10` cut -c$2-$p2 file2.txt > result.txt; done <file1.txt
This last command gives me an error message:
cut: invalid range with no endpoint: - Try 'cut --help' for more information. expr: non-integer argument