Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Take the 2nd line from the bottom Post 302761153 by Pieter0815 on Friday 25th of January 2013 08:31:38 AM
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.
 

9 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

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. 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

7. 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

8. 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

9. 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
TAIL(1) 						    BSD General Commands Manual 						   TAIL(1)

NAME
tail -- display the last part of a file SYNOPSIS
tail [-F | -f | -r] [-q] [-b number | -c number | -n number] [file ...] DESCRIPTION
The tail utility displays the contents of file or, by default, its standard input, to the standard output. The display begins at a byte, line or 512-byte block location in the input. Numbers having a leading plus ('+') sign are relative to the beginning of the input, for example, ``-c +2'' starts the display at the second byte of the input. Numbers having a leading minus ('-') sign or no explicit sign are relative to the end of the input, for example, ``-n 2'' displays the last two lines of the input. The default start- ing location is ``-n 10'', or the last 10 lines of the input. The options are as follows: -b number The location is number 512-byte blocks. -c number The location is number bytes. -f The -f option causes tail to not stop when end of file is reached, but rather to wait for additional data to be appended to the input. The -f option is ignored if the standard input is a pipe, but not if it is a FIFO. -F The -F option implies the -f option, but tail will also check to see if the file being followed has been renamed or rotated. The file is closed and reopened when tail detects that the filename being read from has a new inode number. The -F option is ignored if reading from standard input rather than a file. -n number The location is number lines. -q Suppresses printing of headers when multiple files are being examined. -r The -r option causes the input to be displayed in reverse order, by line. Additionally, this option changes the meaning of the -b, -c and -n options. When the -r option is specified, these options specify the number of bytes, lines or 512-byte blocks to display, instead of the bytes, lines or blocks from the beginning or end of the input from which to begin the display. The default for the -r option is to display all of the input. If more than a single file is specified, each file is preceded by a header consisting of the string ``==> XXX <=='' where XXX is the name of the file unless -q flag is specified. EXIT STATUS
The tail utility exits 0 on success, and >0 if an error occurs. SEE ALSO
cat(1), head(1), sed(1) STANDARDS
The tail utility is expected to be a superset of the IEEE Std 1003.2-1992 (``POSIX.2'') specification. In particular, the -F, -b and -r options are extensions to that standard. The historic command line syntax of tail is supported by this implementation. The only difference between this implementation and historic versions of tail, once the command line syntax translation has been done, is that the -b, -c and -n options modify the -r option, i.e., ``-r -c 4'' displays the last 4 characters of the last line of the input, while the historic tail (using the historic syntax ``-4cr'') would ignore the -c option and display the last 4 lines of the input. HISTORY
A tail command appeared in PWB UNIX. BSD
June 29, 2006 BSD
All times are GMT -4. The time now is 03:22 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy