#set the work directory to where the files are before using the script: setwd("path_to_directory")

rm(list = ls())

File_name <- readline("Enter the file name:")
File_nameTXT <- paste(File_name,".txt",sep = "")
File_nameCSV <- paste(File_name,".csv",sep = "")
mydata = read.table(file = File_nameTXT)
HO<-c(mydata$V2[1:length(mydata$V2)])
UE = table(HO)
write.csv(UE, file = File_nameCSV)