grep will not open text file that I created using split command in linux
1
0
Entering edit mode
18 months ago
psb7 ▴ 20

Does anyone know why 'grep' will not recognise a text file that I used this script to split into a series of truncated text file with just 1000 lines from a largerfile:

split -l 1000 -d  file.txt file --additional-suffix=.txt, (#file00.txt, file01.txt, file02.txt...file26.txt)


However, when I use 'grep' on the same text file content of 1000 lines that I copy from a larger text file and save as another text file, then 'grep' recognises it and carries out the action that I want?

grep split • 687 views
0
Entering edit mode

0
Entering edit mode

how is it related to bioinformatcs ?

1
Entering edit mode
18 months ago
psb7 ▴ 20

I opened in notepad and in the bottom right corner it told me the split text file created a windows cr/lf file, whereas the original was a unix lf file, both are UTF-8, so the below script fixed the file and now my grep command works:

awk '{ sub("\r\$", ""); print }' windows.txt > unix.txt


Alternate methods to convert windows to unix and vice versa can be found here: https://www.maketecheasier.com/convert-files-from-linux-format-windows/