Write the first 10 characters of each line to a new file using bash
I apologize for using code notation with my file content, but the formatting was weird otherwise.
I have a line file 6,6494,940 containing the following:
@MSQ-M01247R:81:000000000-ACWD8:1:1101:11811:1088 2:N:0:
CCCCCTCTTCCCTTTCTTCCCCCCTCTTTCTTCTTTCTCTTTTCTCCCTCTCCTTTTTTTCTCCTTTTTTTCCTTT
+
############################################################################
I want to write the first 10 characters of each line to a new file in order:
@MSQ-M0124
CCCCCTCTTC
+
##########
I used the following bash script:
while read line
do
long=$line
short=${long:0:10}
echo ${short}
done < $1
With the following command:
./bashscript.sh fileread.fastq >> filewrite.fastq
results
Something went wrong. My new / write file had 628,429,568 but it should have had 66,494,940, just like the original / read file. So it looks like it was continuing the cycle.
When I use the head command on the new / write file, I get:
@MSQ-M0124
CCCCCTCTTC
+
##########
@MSQ-M0124
CCTCCTCCTT
+
##########
@MSQ-M0124
CCTTCTTCTT
When I use the tail command, I get:
CCCCCGGGGG
+
CCCCCGGGGG
GAGTCGTCTG
+
CCCCCGGGGG
+
CCCCCGGGGG
GAGTCGTCTG
+
CCCCCGGGGG
+
CCCCCGGGGG
GAGTCGTCTG
+
+3
source to share