x<-readLines("https://www.sec.gov/Archives/edgar/full-index/2021/QTR1/company.idx") x2<-gsub("#","!",x) write.table(x2,file="t.txt",quote=F,row.names=F) myWidths<-c(62, 9, 10, 15, 45) x3<-read.fwf('t.txt',myWidths,skip=11) colnames(x3)<-c("NAME","FORM","CIK","DATEFILED","LOCATION") path<-"https://www.sec.gov/Archives/edgar/full-index/" y=2020 q=1 infile<-paste0(path,y,"/QTR",q,"/company.idx") outfile<-paste0('index',y,'Q',q,'.RData') x<-readLines(infile) x2<-gsub("#","!",x) write.table(x2,file="t.txt",quote=F,row.names=F) myWidths<-c(62, 9, 10, 15, 45) x3<-read.fwf('t.txt',myWidths,skip=11) colnames(x3)<-c("NAME","FORM","CIK","DATEFILED","LOCATION") a<-gsub(".*/","",x3$LOCATION) b<-gsub(".txt","",a) name<-gsub("!","#",x3$NAME) .x<-data.frame(name,x3[,2:4],b) colnames(.x)<-colnames(x3) save(.x,file=outfile)