Showing posts with label Shell Scripts. Show all posts
Showing posts with label Shell Scripts. Show all posts
Saturday, February 17, 2018
Today let us see the various operations that can be performed using sed for printing or displaying lines from a file. First let us understand the format of print in sed.
We can display the content of file using the line number or a pattern.
“p” is a command for printing the data from the pattern buffer. “-n” is used to suppress automatic printing of pattern space.
I have created a file mytestfile.txt to illustrate the examples. (NOTE : I am executing the commands online in http://www.compileonline.com/execute_bash_online.php)
SED Eg 1 - Example file
How to display a particular line from a file using sed?
We all know that the head and tail command allows us to view from the top or the bottom of the file. But what if we want to view a particular line from middle of the file? This problem can be solved by using the below sed command.
This command will print the ‘N’th line of the file.
For example, if we want to see the 5th line of the file mytestfile.txt, then we use
SED Eg 2 - Print particular line using sed
How to display a range of lines from a file using sed?
This command will print the lines from M to N.
For example, if we want to view 2 to 5 lines of the file mytestfile.txt, then we use
SED Eg 3 - Print range of lines using sed
How to display more than one range of lines from a file using sed?
This command will print the lines from M to N and from P to Q. “-e” option means execute.
For example, if we want to view lines from 2 to 5 and from 8 to 9 of the file mytestfile.txt, then we use
SED Eg 4 - Print different range of lines using sed
How to display the entire file except a single line using sed?
This command will delete the line M and print the rest of the file. “-d” option means delete.
For example, if we do want to delete line 4 from of the file mytestfile.txt, then we use
SED Eg 5 - Print entire file excluding a single line using sed
How to display the entire file except a range of lines using sed?
This command will delete the lines from M to N and print the rest of the file.
For example, if we do not want to view lines from 2 to 5 of the file mytestfile.txt, then we use
SED Eg 6 - Print entire file excluding range of lines using sed
How to print every Nth line from a particular line using sed?
This command will print every Nth line starting from M line. This command can be used to print odd or even lines in a file.
For example, if we want to view every 2nd line starting from 4th line of the file mytestfile.txt, then we use,
The command to view only even lines of file is shown below.
SED Eg 7 - Print Nth line from particular line using sed
The command to view only odd lines of file is shown below.
SED Eg 8 - Print only even lines using sed
SED Eg 9 - Print only odd lines using sed
How to print the last line of the file using sed?
This command will print the last line of the file.
SED Eg 10 - Print last line using sed
How to print from Nth line to the last line of a file using sed?
This command will print from Nth line to the last line of the file.
For example, if we want to view from 7th line till the end of the file mytestfile.txt, then we use,
SED Eg 11 - Print from Nth line to last line using sed
In the next post, I will show examples of printing lines from a file based on pattern.
Saturday, February 17, 2018 by Team search · 0
Monday, September 9, 2013
The
concurrent request can be submitted via shell script. This can be done by a
standard utility named CONSUB. It can be used to schedule a request
too.
In
this post, I tried providing few details about it.
The syntax for CONCSUB is given below:
CONCSUB APPS username APPS password
responsibility application short name
responsibility name
username
[WAIT=N|Y|]
CONCURRENT
program application short name
program name
[PROGRAM_NAME=””]
[REPEAT_TIME=]
[REPEAT_INTERVAL=]
[REPEAT_INTERVAL_UNIT=< resubmission unit>]
[REPEAT_INTERVAL_TYPE=< resubmission type>]
[REPEAT_END=]
[START=]
[IMPLICIT=< type of concurrent request>
[ ... ]
The syntax for CONCSUB is given below:
CONCSUB APPS username APPS password
responsibility application short name
responsibility name
username
[WAIT=N|Y|
CONCURRENT
program application short name
program name
[PROGRAM_NAME=”
[REPEAT_TIME=
[REPEAT_INTERVAL=
[REPEAT_INTERVAL_UNIT=< resubmission unit>]
[REPEAT_INTERVAL_TYPE=< resubmission type>]
[REPEAT_END=
[START=
[IMPLICIT=< type of concurrent request>
[
These
are the compulsory Parameters:
PARAMETER
|
DESCRIPTION
|
ORACLE ID
|
Username and
Password of the ORACLE ID for Applications, separated by a slash (“/”). This
would be apps/appspass
|
Responsibility Application Short Name
|
Enter the short name of the application for your
responsibility. This name, along with your responsibility name, will be used
to select a responsibility for your request to run in. eg : SYSADMIN
|
Responsibility Name
|
This name, along with your responsibility
application short name, will be used to select a responsibility for your
concurrent request to run in.
eg : ”System Administrator” |
User name
|
Enter the name of your Application Object Library
user. This name will be used to update the Who information for any data your
concurrent manager changes.
eg : SYSADMIN |
CONCURRENT
|
A flag that separates the program–specific
parameters from the operating system parameters.
|
Program application short name
|
The application short name of your concurrent
program.
eg : FND |
Program name
|
The uppercase name of your program. It must be
the short name that you enter in the Concurrent Programs window when defining
a concurrent program.
|
Monday, September 9, 2013 by Team search · 0
Friday, June 14, 2013
We
had a requirement to end a host based concurrent program to end up in warning
status on the failure of a custom validation. After googling and metalink,
finally wrote a reusable function on Shell script to accomplish the purpose.
Here, I have shared the same,
#! /usr/bin/ksh # #************************************************************************************************ # MODIFICATION HISTORY # # Person Version Date Comments # --------- -------- ------- ------------------------------------------------------------ # Teamsearch 0.1 14/06/2013 Initial creation #************************************************************************************************ # #Function Delcaration # # Set concurrent completion status and exit function # exit_warning() { date RC=`sqlplus -s $FCP_LOGIN << EOF VAR RetCode NUMBER Declare lv_session_id NUMBER; lv_cmplte_code VARCHAR(10); lv_req_id NUMBER := $FCP_REQID; lv_resp_id NUMBER; lv_prog_appl_id NUMBER; lv_conc_prog_id NUMBER; lv_resp_appl_id NUMBER; lv_login_id NUMBER; lv_user_id NUMBER := $FCP_USERID; Begin :RetCode := 0; SELECT program_application_id, concurrent_program_id, responsibility_application_id, responsibility_id, conc_login_id INTO lv_prog_appl_id, lv_conc_prog_id, lv_resp_appl_id, lv_resp_id, lv_login_id FROM fnd_concurrent_requests WHERE request_id = lv_req_id; XX_INT_CMN_PKG.InitSession( lv_session_id, lv_user_id, lv_login_id, lv_resp_id, lv_resp_appl_id, lv_req_id, lv_prog_appl_id, lv_conc_prog_id ); If lv_session_id Is Not NULL Then If NOT FND_CONCURRENT.SET_COMPLETION_STATUS( 'WARNING', NULL ) Then :RetCode := 2; End If; Else :RetCode := 2; End If; End; / EXIT :RetCode EOF` RC=$? exit $RC } #Standard parameters FCP_LOGIN=${1} FCP_USERID=${2} FCP_USERNAME=${3} FCP_REQID=${4} #Input Parameters and other standard logic needed as per the program requirements #In my program, i validate many custom rules and update a flag named lv_fail. #Finally, check if the custom flag is 'Y' .. if so end the program in WARNING elif [ "$lv_fail" = "Y" ] then echo "ERROR: Custom Validaiton Failed" exit_warning fi
Friday, June 14, 2013 by Team search · 2
Subscribe to:
Posts (Atom)
Disclaimer
The ideas, thoughts and concepts expressed here are my own. They, in no way reflect those of my employer or any other organization/client that I am associated. The articles presented doesn't imply to any particular organization or client and are meant only for knowledge Sharing purpose. The articles can't be reproduced or copied without the Owner's knowledge or permission.