|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
||||
|
||||
|
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
|
|||
|
|||
|
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 | ||
|
![]() |
| Thread Tools | Search this Thread |
| 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 |
| At The Bottom | Linux Bot | Cartoons for Geeks | 0 | 02-14-2009 05:10 PM |
| Get the line count from 2nd line of the file ? | smc3 | Shell Programming and Scripting | 8 | 06-16-2008 10:59 PM |
|
|