Sponsored Content
Top Forums Shell Programming and Scripting Appending a text to the top of each line Post 303014795 by John K on Wednesday 21st of March 2018 07:59:45 AM
Old 03-21-2018
Appending a text to the top of each line

Platform : Oracle Linux 6.8
Shell : bash

I have a file which has lines like below. These are SELECT queries (SQL)

In each line, I want the word just after FROM keyword to be copied and printed on the top along with the word PROMPT.
The words after FROM clause below are table names. So, they come like <schemaName>.<TableName> .

Both raw and expected output shown below


-- Raw file

Code:
SELECT AREA_ID, CODE, DESCRIPTION FROM SCOTT.SFO_AREA_MST;

SELECT EMP_ID, CODE, NAME, AREA_MST_ID, PARENT_ID FROM SCOTT.SFO_AREA_DTL where order_date > sysdate - 5 ;

SELECT OUTLET_AREA_ID, OUTLET_MST_ID, AREA_ID FROM APP_USR.SFO_OUTLET_AREA_MAPPING;

SELECT AREA_ID, AREA_USER_ID, AREA_MST_ID FROM SCOTT.SFO_USER_AREA_MAPPING;

SELECT EMP_ID, USER_ID, OUTLET_ID, AREA_ID, DEALER_ID FROM HR.EMP_MAPPING;

-- Expected output

Code:
PROMPT SCOTT.SFO_AREA_MST
SELECT AREA_ID, CODE, DESCRIPTION FROM SCOTT.SFO_AREA_MST;

PROMPT SCOTT.SFO_AREA_DTL
SELECT EMP_ID, CODE, NAME, AREA_MST_ID, PARENT_ID FROM SCOTT.SFO_AREA_DTL ;

PROMPT APP_USR.SFO_OUTLET_AREA_MAPPING
SELECT OUTLET_AREA_ID, OUTLET_MST_ID FROM APP_USR.SFO_OUTLET_AREA_MAPPING;

PROMPT SCOTT.SFO_USER_AREA_MAPPING
SELECT AREA_ID, AREA_USER_ID, AREA_MST_ID FROM SCOTT.SFO_USER_AREA_MAPPING;

PROMPT HR.EMP_MAPPING
SELECT EMP_ID, USER_ID, OUTLET_ID, AREA_ID, DEALER_ID FROM HR.EMP_MAPPING;

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Appending Text To Each Line That Matches Grep

I'm currently digging for a way to append a line to a text file where each line begins with the word "setmqaut". This is a continuation of my IBM MQSeries backup script I'm working on to make my life a little easier. What I would like to do is have each line that looks like this: setmqaut -m... (4 Replies)
Discussion started by: sysera
4 Replies

2. Shell Programming and Scripting

Appending the line number and a seperator to each line of a file ?

Hi, I am a newb as far as shell scripting and SED goes so bear with me on this one. I want to basically append to each line in a file a delimiter character and the line's line number e.g Change the file from :- aaaaaa bbbbbb cccccc to:- aaaaaa;1 bbbbbb;2 cccccc;3 I have worked... (4 Replies)
Discussion started by: pjcwhite
4 Replies

3. Shell Programming and Scripting

Appending line ending with '}" to new line

Hello masters. I have a rather simple problem but its been killing me. I have a file "x" with only 1 line inside it. The line looks something like Now this is only part of the line. Its actually about 4000 characters. What i need to do is whenever there is a "}", i need to append the next... (4 Replies)
Discussion started by: aismann
4 Replies

4. UNIX for Dummies Questions & Answers

appending text on top of another file

Dear All, I have two files One is script file in which I am writing commands to append a text in a normal file. I want to insert the text on top of the file. I dont want to use sed and awk commands nor temp file. is it possible? (3 Replies)
Discussion started by: anjali
3 Replies

5. Shell Programming and Scripting

sed: appending alternate line after previous line

Hi all, I have to append every alternate line after its previous line. For example if my file has following contents line 1: unix is an OS line 2: it is open source line 3: it supports shell programming line 4: we can write shell scripts Required output should be line1: unix is an OS it is... (4 Replies)
Discussion started by: rish_max
4 Replies

6. Shell Programming and Scripting

awk;sed appending line to previous line....

I know this has been asked before but I just can't parse the syntax as explained. I have a set of files that has user information spread out over two lines that I wish to merge into one: User1NameLast User1NameFirst User1Address E-Mail:User1email User2NameLast User2NameFirst User2Address... (11 Replies)
Discussion started by: walkerwheeler
11 Replies

7. Shell Programming and Scripting

Appending the first word of each line to the end of each line

Hi Experts, Am relatively new to shell programming so would appreciate some help in this regard. I am looking at reading from a file, line by line, picking the first word of each line and appending it to the end of the line. Any suggestions? INPUT FILE - 3735051 :... (7 Replies)
Discussion started by: hj007
7 Replies

8. Shell Programming and Scripting

Increasing a number and appending it to next line of a text file

Hi all, I have text file having a number P100. what i need is when i run a script, it should add 1 to the above number and append it to the next line of a same text file.. when i use the script next time it should check the last line and add 1 to the last number and so on.. like the text... (5 Replies)
Discussion started by: smarty86
5 Replies

9. UNIX for Dummies Questions & Answers

sed - appending text

Hey all I am trying to append a file called datebook.txt. I want to append the end of each line containing the name Fred with three ***. I believe I need to make the * loose its meta character meaning in addition to using the append command. I have tried several variations of this command and I... (3 Replies)
Discussion started by: citizencro
3 Replies

10. Shell Programming and Scripting

Grabbing top line of text in a file and setting it to a variable

If I have a txt file with test.txt somelineoftext and I want to set that line of text to variable in a script: so #!/bin/bash var='' becomes #!/bin/bash var='somelineoftext' (3 Replies)
Discussion started by: digitalviking
3 Replies
ROLLBACK TO 
SAVEPOINT(7) SQL Commands ROLLBACK TO SAVEPOINT(7) NAME
ROLLBACK TO SAVEPOINT - roll back to a savepoint SYNOPSIS
ROLLBACK [ WORK | TRANSACTION ] TO [ SAVEPOINT ] savepoint_name DESCRIPTION
Roll back all commands that were executed after the savepoint was established. The savepoint remains valid and can be rolled back to again later, if needed. ROLLBACK TO SAVEPOINT implicitly destroys all savepoints that were established after the named savepoint. PARAMETERS
savepoint_name The savepoint to roll back to. NOTES
Use RELEASE SAVEPOINT [release_savepoint(7)] to destroy a savepoint without discarding the effects of commands executed after it was estab- lished. Specifying a savepoint name that has not been established is an error. Cursors have somewhat non-transactional behavior with respect to savepoints. Any cursor that is opened inside a savepoint will be closed when the savepoint is rolled back. If a previously opened cursor is affected by a FETCH command inside a savepoint that is later rolled back, the cursor position remains at the position that FETCH left it pointing to (that is, FETCH is not rolled back). Closing a cursor is not undone by rolling back, either. A cursor whose execution causes a transaction to abort is put in a cannot-execute state, so while the transaction can be restored using ROLLBACK TO SAVEPOINT, the cursor can no longer be used. EXAMPLES
To undo the effects of the commands executed after my_savepoint was established: ROLLBACK TO SAVEPOINT my_savepoint; Cursor positions are not affected by savepoint rollback: BEGIN; DECLARE foo CURSOR FOR SELECT 1 UNION SELECT 2; SAVEPOINT foo; FETCH 1 FROM foo; ?column? ---------- 1 ROLLBACK TO SAVEPOINT foo; FETCH 1 FROM foo; ?column? ---------- 2 COMMIT; COMPATIBILITY
The SQL standard specifies that the key word SAVEPOINT is mandatory, but PostgreSQL and Oracle allow it to be omitted. SQL allows only WORK, not TRANSACTION, as a noise word after ROLLBACK. Also, SQL has an optional clause AND [ NO ] CHAIN which is not currently supported by PostgreSQL. Otherwise, this command conforms to the SQL standard. SEE ALSO
BEGIN [begin(7)], COMMIT [commit(7)], RELEASE SAVEPOINT [release_savepoint(7)], ROLLBACK [rollback(7)], SAVEPOINT [savepoint(7)] SQL - Language Statements 2010-05-14 ROLLBACK TO SAVEPOINT(7)
All times are GMT -4. The time now is 12:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy