bash script to display tail

Hi everyone, I'm trying to write a script to format a file using unix2dos. I want to output all but the first 14 lines in a file. Then I want to pipe this to unix2dos to convert the output to a file that's easily readable on windows. Here's what I have:

export Lines=`wc -l < $1`
export Lines=`expr $Lines - 14`
tail -n $Lines $1 | unix2dos print.txt

It keeps giving me errors though. Any thoughts?

Gives you what errors?

---------- Post updated at 04:03 PM ---------- Previous update was at 04:00 PM ----------

Anyway, after checking some manpages, depending on what version of tail you have you might be able to do this:

tail -n +15 < inputfile | sed 's/$/\r//' > winfile

+15 as in, start printing at line 15, ignoring lines 1-14..

Don't even need unix2dos.

What does the whole " | sed 's/$/\r//' > winfile" part do?

It removes carriage returns (\r (^M)) from the end of lines.

Unix text files are usually very easily readable on Windows, if you change from Notepad as your default application for viewing text files.

I just tried that, and it reports:

sed: -e expression #1, char 8: unknown option to `s'
: command not found

Post exactly what you tried (using code tags ).

I made the script file cv.sh:

tail -n +15 < $1 | sed 's/$/\r//' > winfile

Then on the command line I typed:

./cv.sh test.cpp

There is a typo in the sed command. Should contain only three slashes, not four. Should be :

sed 's/$/\r/' 

instead.
This command will add a carriage return (\r) to the end of line ($), which will make it windows-like.

When I said "remove", I meant "add" (being unix2dos, not dos2unix):slight_smile:

There's a slash too many:

... | sed 's/$/\r/'

Ok, it works pretty good, except a couple things:
Instead of the output being

winfile

it comes out as

winfile?

.
After entering the command at the command line, it responds:

: command not found

.
but looking in "winfile?", the command executed beautifully.

Let me guess, you edited the script in Notepad? Your file is probably named "winfile\r"

Not in notepad, in vim. Somehow it had saved it as a dos file. I used unix2dos on it and now it works flawlessly though. Thanks for the help everyone. :smiley: