Using cut command in a fixed length file

Hi,

I have a file which have set of rows and has to create separate files based on the id.

Eg:

     001_AHaris020
     001_ATony030
     002_AChris090
     002_ASmit060
     003_AJhon001

Output: I want three files like 001_A.txt, 002_A.txt and 003_A.txt.

001_A.txt should have

     Haris020
     Tony030

002_A.txt should have

     Chris090
     Smit060

003_A.txt should have

      Jhon001

Please give some ideas using cut command having in the while loop...

while read line;do
    grep "001" $line|awk -F "_[0-9]" '{print $NF}' >> File1.txt
    grep "002" $line|awk -F "_[0-9]" '{print $NF}' >> file2.txt
done<Inputfile
file1:
001_AHaris020
001_ATony030
002_AChris090
002_ASmit060
003_AJhon001

while read LINE; do
  echo $LINE | cut -c6- >> $(echo $LINE | cut -c1-5).txt
done < file1

$ cat 001_A.txt 
Haris020
Tony030

$ cat 002_A.txt 
Chris090
Smit060

$ cat 003_A.txt 
Jhon001

tHANKS

Or using parameter expansion (without cut).

while read line;do echo ${line:5} >> ${line:0:5}.txt;done < infile

... faster and shorter :wink: