I am using

a=`head -1 Rt.in` 

to get first value from my file and I am saving it as a variable then I am using same variable to tail -$a to tail last lines from my input. But it is giving an error:

tail: illegal option -- -53\r.

My input file has 4 columns from the third row onwards.

Here is a part of script I am using :

a=`head -1 Rt.in`
echo $a
tail -$a Rt.in

and the error in output I am getting is this:

tail: illegal option -- -53\r

And the part of input file is as follows:

H    9.155963    1.289174   11.531518
H    9.004353    2.726286   11.683448
N   11.762550    3.890769   11.785241
N   10.610393    3.635048    9.544268
N   10.745642    1.175050    9.076323
N   13.210069    2.309946    9.848128
N   12.319480    0.955257   11.800435
C   12.359945    3.942548   12.929277
C   11.267322    5.027779   11.274755
H    9.052185    4.031311    6.865735
C   10.031631    3.303244    8.416945
C   10.093512    1.894663    8.164740
C    9.546565    1.312421    7.090592

There are 53 such lines.

Can anybody will tell me why I am getting this error and how can I remove it??
If I run above script using pipes directly in terminal I am getting error as tail: -: No such file or directory and then list of few atoms.

  • Your Rt.in file was probably created on Windows. Use dos2unix to create a new file that Unix tools will understand. – Mark Plotnick Nov 4 '15 at 10:57
  • dking, if you need to edit your question to add the '53' at the top of the input file, click the edit link at the bottom-left of it, or this copy – Jeff Schaller Nov 4 '15 at 13:57
  • Hi i did not create this file on windows i created it on mac – dking Dec 11 '15 at 12:21

The number of lines should not be the parameter it should be:

tail -n $a Rt.in

Now you get the number of last lines that is defined in the first line of your file. This -n should also be used with your head command.

  • Yes i tried that too but it is giving error tail: illegal offset -- 53\r. – dking Nov 4 '15 at 10:45
  • Can anybody edit my question there is 53 at the beginning of my input file – dking Nov 4 '15 at 10:47
  • tail -5 and head -9 (using whatever digits) work and are the original options for these commands and still work. These options are no longer documented for some reason unknown to me. – RobertL Nov 4 '15 at 11:14
  • @dking the answer is in the comment on your question. You have incorrect line endings on Rt.in probably because it was created on Windows. – RobertL Nov 4 '15 at 11:26
  • @RobertL - this answer is correct. you should review the standard, use -n. – mikeserv Nov 4 '15 at 14:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.