Take the 2nd line from the bottom | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Take the 2nd line from the bottom

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-25-2013
Pieter0815 Pieter0815 is offline
Registered User
 
Join Date: Oct 2012
Last Activity: 7 March 2014, 5:28 AM EST
Posts: 9
Thanks: 1
Thanked 0 Times in 0 Posts
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.
Sponsored Links
    #2  
Old 01-25-2013
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
 
Join Date: Dec 2007
Last Activity: 21 October 2014, 10:08 AM EDT
Location: Out running a Marathon.
Posts: 2,332
Thanks: 73
Thanked 155 Times in 144 Posts

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.
Sponsored Links
    #3  
Old 01-25-2013
grep_me grep_me is offline
Registered User
 
Join Date: Oct 2008
Last Activity: 6 August 2014, 9:06 AM EDT
Location: INDIA
Posts: 43
Thanks: 8
Thanked 3 Times in 3 Posts
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`

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
1st column,2nd column on first line 3rd,4th on second line ect... batcho Shell Programming and Scripting 6 04-06-2012 09:20 AM
Search for string and print top and bottom line bombcan Shell Programming and Scripting 1 09-13-2011 08:38 AM
Get the bottom line of a file to the top of the file Shellslave Shell Programming and Scripting 5 11-04-2009 04:02 AM
Get the line count from 2nd line of the file ? smc3 Shell Programming and Scripting 8 06-16-2008 10:59 PM



All times are GMT -4. The time now is 09:34 PM.