nthline()

Return specified lines from a text string.

Syntax

nthline(text,lines,[separator])

Parameter

Parameter

Definition

text

text to be separated into lines by the nthline() function The text can be a text string enclosed in double quotation marks, or one or more PSL commands that produce text as output.

lines

integer list specifying the line numbers nthline() should look for in text

*Valid Values* 
x,y line x and line y 
x-y all lines from x to y inclusive 
-x all lines from 1 to x inclusive 
x- all lines from x to EOF character inclusive

separator

optional character that should be placed between each field of nthline() output

*Default* 
new-line character (\n).

Description

The nthline() function returns the lines of text separated by new-line characters. If you specify a separator, the nthline() function will use separator to separate lines.

Note

The difference between the nthlinef() and nthline() functions is as follows:

 

  • The nthlinef() function treats each new-line character as a line.
  • The nthline() function treats only a nonempty line (that is, a line with a nonnew-line character preceding a new-line character) as a line.

 

BMC Software recommends you use nthlinef() function to be consistent with other PSL functions.

Example

The following PSL script prints the top five processes executing on a Unix system.

# print the top five processes
print(nthline(system("ps -eaf"),"2-6"));

The following example illustrates the difference between the nthline() function and the nthlinef() function:

string = "abc\n\n123\nxyz";
A = nthline(string,3);
B = nthlinef(string,3);
print("nthline() 3rd string argument is : ",A,"\n");
print("nthlinef() 3rd string argument is : ",B,"\n");

Was this page helpful? Yes No Submitting... Thank you

Comments