bash script to display tail


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting bash script to display tail
# 1  
Old 04-08-2011
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:
Code:
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?
# 2  
Old 04-08-2011
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:

Code:
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.
# 3  
Old 04-08-2011
What does the whole " | sed 's/$/\r//' > winfile" part do?
# 4  
Old 04-08-2011
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.
# 5  
Old 04-08-2011
I just tried that, and it reports:

sed: -e expression #1, char 8: unknown option to `s'
: command not found
# 6  
Old 04-08-2011
Quote:
Originally Posted by LuminalZero
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 ).
# 7  
Old 04-08-2011
I made the script file cv.sh:

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

Then on the command line I typed:
Code:
./cv.sh test.cpp

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

How to display certain line of file only using head or tail in 1 command?

First month learning about the Linux terminal and it has been a challenge yet fun so far. We're learning by using a gameshell. I'm trying to display a certain line ( only allowed 1 command ) from a file only using the head or tail. I'm pretty about this answer: head -23 history.txt | tail -1... (1 Reply)
Discussion started by: forzatekk
1 Replies

2. Shell Programming and Scripting

Bash script to display result in table

My script gives the following result. Is it possible to display the same in table format ? 1. rex_best Latest feeds are not avaialable. The last feed was generated on 2012-05-17 File Name = ekb_best_20120517_010949_665.tar.gz The Number of entry elements = 4209539 2. rex_genre Latest... (2 Replies)
Discussion started by: kishorekumar87
2 Replies

3. UNIX for Dummies Questions & Answers

head\tail how to display middle lines

hay i need to display middle line: 1 2 3 4 5 how can i display 3-4? (6 Replies)
Discussion started by: margan_ron
6 Replies

4. Shell Programming and Scripting

How to refresh a graphical display through bash script

Hi folks , I need to display a message graphically using a messagebox or textbox through bash script. However the message should be keep changing every 4 secs . I input the message from a file and use "gxmessage" to display it . gxmessage -nofocus -center -title "Welcome screen" -geometry... (3 Replies)
Discussion started by: ddspark
3 Replies

5. Shell Programming and Scripting

Display Specific line number using tail command

Hi , 1)i want to display specific line number using tail command. e.g. display 10 line from end. Please help... 2)Want to display line 10 to 15 (from end)using tail command) (2 Replies)
Discussion started by: vivek1489
2 Replies

6. Shell Programming and Scripting

bash script tail when string found do something

Okay, I have two scripts, the first one does some stuff, and comes to a point where it has this: Right here it runs a quick script to start something that writes to a log file. /usr/bin/tail -f ${pathVar}/nohup_${servVar}.out | while read -r line do ] && continue cd ${pathVar}... (0 Replies)
Discussion started by: cbo0485
0 Replies

7. Shell Programming and Scripting

Display runnning countdown in a bash script?

I am looking for a way to display on a single line, a running countdown for a given amount of time in a terminal using a bash script. I am looking for this to use as part of a larger bash script that captures Video. The script sets up a bunch of parameters for DVgrab, and one of the parameters... (11 Replies)
Discussion started by: Starcast
11 Replies

8. Shell Programming and Scripting

tail display ....in perl

hi we have 3 servers and we have a script to monitor cpu usage of all 3 servers and writes into one file on one of the server where we monitor all those servers ( by doing tail -f filename ) so we decided to create script ( perl ) that will read values from this file and display it should be like... (2 Replies)
Discussion started by: zedex
2 Replies

9. UNIX for Dummies Questions & Answers

how to display line number for tail -f

Hi, Just wonder if there is any quick way to display line number when monitoring a log file with tail -f? (4 Replies)
Discussion started by: iengca
4 Replies

10. Shell Programming and Scripting

Tail-alike display of new files in directory

The system I work on, produces several kinds of status-files in a single directory. I would like to be able to see the files as they are added to this directory. I was wondering if it would be possible to get a "tail -f" alike view of the ls-command, in such a way that a newly added file is... (4 Replies)
Discussion started by: rschelkers
4 Replies
Login or Register to Ask a Question

Featured Tech Videos