Take the 2nd line from the bottom


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Take the 2nd line from the bottom
# 1  
Old 01-25-2013
Take the 2nd line from the bottom

Dear friendly helpers,

I want to compare the last line and the 2.nd line from the bottom later with a calculation. The rest of the script is working. What is wrong with my solution?

I want to take the 2nd line from the bottom. And I do not know the command.
TAIL -2 is wrong because it takes the 2 bottom lines.
So I tried to take the 2 lines from the bottom with tail -2 and later the 1. line with head -1.


Code:
SIZE_SCR=`grep ^scr /rsi/logs/csc_summary_size_check.log | tail -1 | cut -d";" -f4 | cut -b1-3`
SIZE_VORHER_SCR=`grep ^scr /rsi/logs/csc_summary_size_check.log | tail -2 | cut -d";" -f4 | cut -b1-3 | head -1`

Thank you for helping.
# 2  
Old 01-25-2013
Code:
tail -2 <input.txt | head -1

will give you the 2nd to last line

Since do not know the source for you lengthy command, cannot comment on what else might be wrong.
# 3  
Old 01-25-2013
Looks like you are using a regular expression with grep. (if ^ is part of data, escape the character )
Try using egrep and with quotes

Code:
SIZE_SCR=`egrep '^scr' /rsi/logs/csc_summary_size_check.log | tail -1 | cut -d";" -f4 | cut -b1-3`
SIZE_VORHER_SCR=`egrep '^scr' /rsi/logs/csc_summary_size_check.log | tail -2 | cut -d";" -f4 | cut -b1-3 | head -1`

 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How do we display specific row of an output from bottom given line number?

I pass a number to my script. Passing "1" below. ./getfile.sh 1 echo "User entered: $1" ls -ltr *.conf | sed -n '$p' I wish to use ls -ltr i.e list files in ascending order of time the latest showing at the bottom of the output. Number 1 should get me the last row of ls -ltr output i.e... (9 Replies)
Discussion started by: mohtashims
9 Replies

2. UNIX for Beginners Questions & Answers

How to get 2nd last column of the line- UNIX?

I want to retrieve Status from below example. Columns numbers will be dynamic but Status will always be 2nd last- JobName StartTime EndTime Status ExitCode autorep -j $jobName | grep '^FR' | awk -F' ' '{print $2}' The above code gives me the 2nd column from start of the line. (7 Replies)
Discussion started by: Tanu
7 Replies

3. Shell Programming and Scripting

How to read file line by line and compare subset of 1st line with 2nd?

Hi all, I have a log file say Test.log that gets updated continuously and it has data in pipe separated format. A sample log file would look like: <date1>|<data1>|<url1>|<result1> <date2>|<data2>|<url2>|<result2> <date3>|<data3>|<url3>|<result3> <date4>|<data4>|<url4>|<result4> What I... (3 Replies)
Discussion started by: pat_pramod
3 Replies

4. Shell Programming and Scripting

1st column,2nd column on first line 3rd,4th on second line ect...

I need to take one column of data and put it into the following format: 1st line,2nd line 3rd line,4th line 5th line,6th line ... Thanks! (6 Replies)
Discussion started by: batcho
6 Replies

5. Shell Programming and Scripting

Search for string and print top and bottom line

Hi Folks I need a one liner to parse through a log and if the string is found print the line above, the line with the string and the line below. example: The ball is green and blue Billy through the ball higer. Jane got hurt with the ball. So if I search for Billy I would need the 3... (1 Reply)
Discussion started by: bombcan
1 Replies

6. UNIX for Dummies Questions & Answers

Help with editing 2nd line after match

Hi All I would like to break down each next line that matches SK1.chr* in this case NNNNNN.... into 100 characters each after SK1.chr*... (3 Replies)
Discussion started by: pawannoel
3 Replies

7. Shell Programming and Scripting

perl search and replace - search in first line and replance in 2nd line

Dear All, i want to search particular string and want to replance next line value. following is the test file. search string is tmp,??? ,10:1 "???" may contain any 3 character it should remain the same and next line replace with ,10:50 tmp,123 --- if match tmp,??? then... (3 Replies)
Discussion started by: arvindng
3 Replies

8. Shell Programming and Scripting

Get the bottom line of a file to the top of the file

Hi, i have a small requirement where i have to get the bottom most line from a file to the topmost position. a small example is shown below.. $ cat beep.txt It is first documented as being played in southern England. In the 16th century. By the end of the 18th century, Cricket is a... (5 Replies)
Discussion started by: Shellslave
5 Replies

9. Shell Programming and Scripting

Get the line count from 2nd line of the file ?

Hi, I want to get the line count of the file from the 2nd line of the file ? The first line is header so want to skip that. Thanks. (8 Replies)
Discussion started by: smc3
8 Replies
Login or Register to Ask a Question