grep will not open text file that I created using split command in linux
1
0
Entering edit mode
2.7 years 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 • 989 views
ADD COMMENT
0
Entering edit mode

This is not reproducible. Please add data examples.

ADD REPLY
0
Entering edit mode

how is it related to bioinformatcs ?

ADD REPLY
1
Entering edit mode
2.7 years ago
psb7 ▴ 20

I have the answer:

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/

ADD COMMENT

Login before adding your answer.

Traffic: 2423 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6