0

I have a txt file with an #header. If I use cat the output is only the first and the last lines despite the file being a few hundred lines long. What is going on?

EDIT

A minimal example is pretty much what you imagine:

file.txt is

#header 2.0
2.0
2.1
2.2
...
...
...
18.2

and the result of cat file.txtis

[Desktop]$ cat file.txt 
#header 2.0
18.2[Desktop]$ 
Jasper
  • 192
  • 8
Manfredo
  • 1,760
  • 4
  • 25
  • 53
  • 1
    Can you provide a [mcve]? No one knows why without being able to reproduce. – iBug Jan 21 '19 at 12:36
  • Without showing your samples of input and error it is quite difficult to even understand problem, Please post samples in code tags(not in images) and let us know then. – RavinderSingh13 Jan 21 '19 at 12:37
  • well, I still can't reproduce the behavior. Can you show us what `type cat` says? Does `cat` behave normally on another file? – iBug Jan 21 '19 at 12:41
  • `[Desktop]$ type cat` produces: `cat is hashed (/bin/cat)` On other files it behaves normally – Manfredo Jan 21 '19 at 12:42
  • Maybe some issue with line breaks, is the file originally from a Mac? What does it look like in Text or some other text editor? – Joakim Danielson Jan 21 '19 at 12:44
  • @Manfredo, could you please check once `cat -v Input_file` and let us know if it has some mysterious characters in it? – RavinderSingh13 Jan 21 '19 at 12:45
  • Yes that was also my guess but it looks normal. It's a file I copied from excel but in textedit it looks normal. `file -i` says `regular file`. – Manfredo Jan 21 '19 at 12:46
  • @RavinderSingh13 There are a lot of `^M1 ^M2 M^3` ecc. characters... How to I correct for that? – Manfredo Jan 21 '19 at 12:48
  • @Manfredo, aah ha, try to remove them by using `tr -d '\r' < Input_file > temp_file && mv temp_file Input_file` and then do `cat Input_file` and let us know then? – RavinderSingh13 Jan 21 '19 at 12:49
  • `tr` did not do the trick for me. I found the best solution to be editing the file in vim as it is described in https://stackoverflow.com/questions/811193/how-to-convert-the-m-linebreak-to-normal-linebreak-in-a-file-opened-in-vim (:%s//\r/g) – Manfredo Jan 21 '19 at 13:16
  • Even better with the utility `dos2unix`, only caveat is that for mac that needs to be `mac2unix file.txt` – Manfredo Jan 21 '19 at 13:22

0 Answers0