0

i create simple shell script (test.sh) to do grep from a big file (source.txt) using 1 file contains with a list of string (list.txt) then put the result to a new file (result.txt). The script is working as expected, but the issue is there is special character shown as question mark on result file (see figure below).

Here is the script :

RES_FILE=result.txt
for i in `cat list.txt`; do echo "############ "$i" ############"; grep $i source.txt; echo ""; done > "$RES_FILE"
echo "DONE"

The file name looks like this :

-rw-r--r-- 1 uatabp1 aimsys 4705499 Jan 19 13:52 source.txt
-rw-r--r-- 1 uatabp1 aimsys      40 Feb 17 14:19 list.txt
-rwxr-xr-x 1 uatabp1 aimsys     421 Feb 20 09:15 test.sh
-rw-r--r-- 1 uatabp1 aimsys   22629 Feb 20 09:34 result.txt??

Why it has question mark on result.txt?

King Goeks
  • 492
  • 4
  • 11
  • 28
  • hi @kdhp, any suggestion how to use Unix (LF) line endings? – King Goeks Feb 20 '17 at 06:33
  • 2
    @KingGoeks: Tell your text editor, that it should use them, when creating a file. – user1934428 Feb 20 '17 at 10:42
  • 1
    Depending on what is being used, the file can be [converted](https://stackoverflow.com/questions/2613800/), written on the machine ([`vi(1)`](http://man.openbsd.org/OpenBSD-current/man1/vi.1) and the like), or the local editor can be reconfigured (as suggested by @user1934428). – kdhp Feb 20 '17 at 17:58
  • 1
    @kdhp: I was also thinking of conversion, but since a file is usually updated from time to time, it's invonvenient to convert it every time. However, I forgot one case, which might cause trouble even with a correctly configured editor: If source management software such as Clearcase, Git or Subversion is used, it could be that on commit/check-in, a trigger would again convert the linefeeds back to CRLF. I was bitten by this at least twice. – user1934428 Feb 21 '17 at 06:26

0 Answers0