将许多 bib tex 文件合并为一个
Merge many bib tex files into one
我有多个像这样的单个 bibtex 文件:
第一个文件:
@article{DBLP:journals/access/AlotaibiAASA20,
author = {Bashayer Alotaibi and
Rabeeh Ayaz Abbasi and
Muhammad Ahtisham Aslam and
Kawther Saeedi and
Dimah Alahmadi},
title = {Startup Initiative Response Analysis {(SIRA)} Framework for Analyzing
Startup Initiatives on Twitter},
journal = {{IEEE} Access},
volume = {8},
pages = {10718--10730},
year = {2020},
url = {https://doi.org/10.1109/ACCESS.2020.2965181},
doi = {10.1109/ACCESS.2020.2965181},
timestamp = {Fri, 07 Feb 2020 12:04:40 +0100},
biburl = {https://dblp.org/rec/journals/access/AlotaibiAASA20.bib},
bibsource = {dblp computer science bibliography, https://dblp.org}
}
第二个文件:
@inproceedings{DBLP:conf/comad/MathewKG020,
author = {Binny Mathew and
Navish Kumar and
Pawan Goyal and
Animesh Mukherjee},
editor = {Rishiraj Saha Roy},
title = {Interaction dynamics between hate and counter users on Twitter},
booktitle = {CoDS-COMAD 2020: 7th {ACM} {IKDD} CoDS and 25th COMAD, Hyderabad India,
January 5-7, 2020},
pages = {116--124},
publisher = {{ACM}},
year = {2020},
url = {https://doi.org/10.1145/3371158.3371172},
doi = {10.1145/3371158.3371172},
timestamp = {Wed, 22 Jan 2020 14:37:05 +0100},
biburl = {https://dblp.org/rec/conf/comad/MathewKG020.bib},
bibsource = {dblp computer science bibliography, https://dblp.org}
}
如何才能全部读取它们(它们在同一路径中)并创建一个新文件,该文件只是所有文件的粘贴。
预期输出示例
@article{DBLP:journals/access/AlotaibiAASA20,
author = {Bashayer Alotaibi and
Rabeeh Ayaz Abbasi and
Muhammad Ahtisham Aslam and
Kawther Saeedi and
Dimah Alahmadi},
title = {Startup Initiative Response Analysis {(SIRA)} Framework for Analyzing
Startup Initiatives on Twitter},
journal = {{IEEE} Access},
volume = {8},
pages = {10718--10730},
year = {2020},
url = {https://doi.org/10.1109/ACCESS.2020.2965181},
doi = {10.1109/ACCESS.2020.2965181},
timestamp = {Fri, 07 Feb 2020 12:04:40 +0100},
biburl = {https://dblp.org/rec/journals/access/AlotaibiAASA20.bib},
bibsource = {dblp computer science bibliography, https://dblp.org}
}
@inproceedings{DBLP:conf/comad/MathewKG020,
author = {Binny Mathew and
Navish Kumar and
Pawan Goyal and
Animesh Mukherjee},
editor = {Rishiraj Saha Roy},
title = {Interaction dynamics between hate and counter users on Twitter},
booktitle = {CoDS-COMAD 2020: 7th {ACM} {IKDD} CoDS and 25th COMAD, Hyderabad India,
January 5-7, 2020},
pages = {116--124},
publisher = {{ACM}},
year = {2020},
url = {https://doi.org/10.1145/3371158.3371172},
doi = {10.1145/3371158.3371172},
timestamp = {Wed, 22 Jan 2020 14:37:05 +0100},
biburl = {https://dblp.org/rec/conf/comad/MathewKG020.bib},
bibsource = {dblp computer science bibliography, https://dblp.org}
}
已编辑:
我测试了下面的代码,它将多个文件合并为一个:
首先,提取 .bib
文件的所有路径("."
如果它们在工作目录中,"path/to/directory/"
或 "/absolute/path/to/directory"
否则:
path_to_bib_files <- list.files(".", pattern="\.bib$", full.names=TRUE)
然后,逐个遍历文件并附加它们:
combined_bib <- ""
for (path_to_bib_file in path_to_bib_files) {
fileCon <- file(path_to_bib_file)
content <- readLines(fileCon)
close(fileCon)
combined_bib <- paste0(combined_bib, "\n", "\n", trimws(paste0(content, collapse="\n")))
}
最后,将合并后的字符串写入文件:
cat(combined_bib, file="combined_references.bib", "\n")
您可以像这样将两个文件的内容连接在一起
big_bib <- c(readLines("bib1.bib"), "\n", readLines("bib2.bib"))
然后像这样写新文件:
writeLines(big_bib, "big_bib.bib")
以下是我的有效步骤。
1.List 所有文件。
list_files<- list.files("path", pattern="\.bib$", full.names=T)
2.Read 所有文件
read_files<-lapply(d,readLines)
3.Unlist 他们
Unlist_files<-unlist(read_files)
4.Export 作为单个对象
write(Unlist_files, file = "path/Bib.bib")
我有多个像这样的单个 bibtex 文件:
第一个文件:
@article{DBLP:journals/access/AlotaibiAASA20,
author = {Bashayer Alotaibi and
Rabeeh Ayaz Abbasi and
Muhammad Ahtisham Aslam and
Kawther Saeedi and
Dimah Alahmadi},
title = {Startup Initiative Response Analysis {(SIRA)} Framework for Analyzing
Startup Initiatives on Twitter},
journal = {{IEEE} Access},
volume = {8},
pages = {10718--10730},
year = {2020},
url = {https://doi.org/10.1109/ACCESS.2020.2965181},
doi = {10.1109/ACCESS.2020.2965181},
timestamp = {Fri, 07 Feb 2020 12:04:40 +0100},
biburl = {https://dblp.org/rec/journals/access/AlotaibiAASA20.bib},
bibsource = {dblp computer science bibliography, https://dblp.org}
}
第二个文件:
@inproceedings{DBLP:conf/comad/MathewKG020,
author = {Binny Mathew and
Navish Kumar and
Pawan Goyal and
Animesh Mukherjee},
editor = {Rishiraj Saha Roy},
title = {Interaction dynamics between hate and counter users on Twitter},
booktitle = {CoDS-COMAD 2020: 7th {ACM} {IKDD} CoDS and 25th COMAD, Hyderabad India,
January 5-7, 2020},
pages = {116--124},
publisher = {{ACM}},
year = {2020},
url = {https://doi.org/10.1145/3371158.3371172},
doi = {10.1145/3371158.3371172},
timestamp = {Wed, 22 Jan 2020 14:37:05 +0100},
biburl = {https://dblp.org/rec/conf/comad/MathewKG020.bib},
bibsource = {dblp computer science bibliography, https://dblp.org}
}
如何才能全部读取它们(它们在同一路径中)并创建一个新文件,该文件只是所有文件的粘贴。
预期输出示例
@article{DBLP:journals/access/AlotaibiAASA20,
author = {Bashayer Alotaibi and
Rabeeh Ayaz Abbasi and
Muhammad Ahtisham Aslam and
Kawther Saeedi and
Dimah Alahmadi},
title = {Startup Initiative Response Analysis {(SIRA)} Framework for Analyzing
Startup Initiatives on Twitter},
journal = {{IEEE} Access},
volume = {8},
pages = {10718--10730},
year = {2020},
url = {https://doi.org/10.1109/ACCESS.2020.2965181},
doi = {10.1109/ACCESS.2020.2965181},
timestamp = {Fri, 07 Feb 2020 12:04:40 +0100},
biburl = {https://dblp.org/rec/journals/access/AlotaibiAASA20.bib},
bibsource = {dblp computer science bibliography, https://dblp.org}
}
@inproceedings{DBLP:conf/comad/MathewKG020,
author = {Binny Mathew and
Navish Kumar and
Pawan Goyal and
Animesh Mukherjee},
editor = {Rishiraj Saha Roy},
title = {Interaction dynamics between hate and counter users on Twitter},
booktitle = {CoDS-COMAD 2020: 7th {ACM} {IKDD} CoDS and 25th COMAD, Hyderabad India,
January 5-7, 2020},
pages = {116--124},
publisher = {{ACM}},
year = {2020},
url = {https://doi.org/10.1145/3371158.3371172},
doi = {10.1145/3371158.3371172},
timestamp = {Wed, 22 Jan 2020 14:37:05 +0100},
biburl = {https://dblp.org/rec/conf/comad/MathewKG020.bib},
bibsource = {dblp computer science bibliography, https://dblp.org}
}
已编辑:
我测试了下面的代码,它将多个文件合并为一个:
首先,提取 .bib
文件的所有路径("."
如果它们在工作目录中,"path/to/directory/"
或 "/absolute/path/to/directory"
否则:
path_to_bib_files <- list.files(".", pattern="\.bib$", full.names=TRUE)
然后,逐个遍历文件并附加它们:
combined_bib <- ""
for (path_to_bib_file in path_to_bib_files) {
fileCon <- file(path_to_bib_file)
content <- readLines(fileCon)
close(fileCon)
combined_bib <- paste0(combined_bib, "\n", "\n", trimws(paste0(content, collapse="\n")))
}
最后,将合并后的字符串写入文件:
cat(combined_bib, file="combined_references.bib", "\n")
您可以像这样将两个文件的内容连接在一起
big_bib <- c(readLines("bib1.bib"), "\n", readLines("bib2.bib"))
然后像这样写新文件:
writeLines(big_bib, "big_bib.bib")
以下是我的有效步骤。
1.List 所有文件。
list_files<- list.files("path", pattern="\.bib$", full.names=T)
2.Read 所有文件
read_files<-lapply(d,readLines)
3.Unlist 他们
Unlist_files<-unlist(read_files)
4.Export 作为单个对象
write(Unlist_files, file = "path/Bib.bib")