Combine 3 files based on a pattern


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Combine 3 files based on a pattern
# 1  
Old 10-09-2013
Oracle Combine 3 files based on a pattern

HI,

I have 3 files that contain the following information (sql output from Oracle database stored in a txt file):

File1.txt :
Code:
alter table "SYS"."INT_COST_PRICE" enable row movement;
alter table "SYS"."INT_SOH" enable row movement;
alter table "SYSMAN"."XX_ACI_SKURTP" enable row movement;

second file contains the following information (source same as above):
File2.txt
Code:
alter table "SYS"."INT_COST_PRICE" shrink space compact;
alter table "SYS"."INT_SOH" shrink space compact;
alter table "SYSMAN"."XX_ACI_SKURTP" shrink space compact;

Third file contains the following information (source same as above):
File3.txt
Code:
alter table "SYS"."INT_COST_PRICE" disable row movement;
alter table "SYS"."INT_SOH" disable row movement;
alter table "SYSMAN"."XX_ACI_SKURTP" disable row movement;

I would like to combine the files together into one single file and having an output as shown below (with blank lines after every 3 lines:

Final_output_file.txt

Code:
alter table "SYS"."INT_COST_PRICE" enable row movement;
alter table "SYS"."INT_COST_PRICE" shrink space compact;
alter table "SYS"."INT_COST_PRICE" disable row movement;

alter table "SYS"."INT_SOH" enable row movement;
alter table "SYS"."INT_SOH" shrink space compact;
alter table "SYS"."INT_SOH" disable row movement;

alter table "SYSMAN"."XX_ACI_SKURTP" enable row movement;
alter table "SYSMAN"."XX_ACI_SKURTP" shrink space compact;
alter table "SYSMAN"."XX_ACI_SKURTP" disable row movement;

Kindly help me out.

Thanks,
Ram.
# 2  
Old 10-09-2013
Try:
Code:
paste -d"\n" file{1..3}
alter table "SYS"."INT_COST_PRICE" enable row movement;
alter table "SYS"."INT_COST_PRICE" shrink space compact;
alter table "SYS"."INT_COST_PRICE" disable row movement;
alter table "SYS"."INT_SOH" enable row movement;
alter table "SYS"."INT_SOH" shrink space compact;
alter table "SYS"."INT_SOH" disable row movement;
alter table "SYSMAN"."XX_ACI_SKURTP" enable row movement;
alter table "SYSMAN"."XX_ACI_SKURTP" shrink space compact;
alter table "SYSMAN"."XX_ACI_SKURTP" disable row movement;

To get those empty lines, create a file4 with three empty lines and run paste -d"\n" file{1..4}
These 2 Users Gave Thanks to RudiC For This Post:
# 3  
Old 10-09-2013
Also for blank lines you can use /dev/null (The empty file)

Code:
paste -d"\n" file{1..3} /dev/null

This User Gave Thanks to Chubler_XL For This Post:
# 4  
Old 10-09-2013
RudiC,

Thank You very much. It helped a lot.

Thanks,
Ram.

---------- Post updated at 11:53 AM ---------- Previous update was at 11:50 AM ----------

Hello Chubler_XL,

Thank You very much. Even better in a single liner.

Thanks,
Ram.
# 5  
Old 10-09-2013
Sorry --- I didn't notice properly...

Thanks Chubler_Xl

Last edited by Akshay Hegde; 10-09-2013 at 05:30 PM.. Reason: (Error correcton) made during posting as noticed by Chubler_XL
# 6  
Old 10-09-2013
Cool solution what does {1} do?

EDIT: Hang on all the file1 stuff is together, it's supposed to be 1 line from each file.
# 7  
Old 10-09-2013
Sorry I didn't notice properly...

Last edited by Akshay Hegde; 10-09-2013 at 05:29 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Combine and complete multiple CSV files based on 1 parameter

I have to create a new CSV file based on the value listed on the 3rd column from different CSV files. This is what I need: 1. I should substitute the first column from each file, excluding the headers, with the file name InputXX. 2. Then, I need to look for rows with 0 on the third column in... (7 Replies)
Discussion started by: Xterra
7 Replies

2. Shell Programming and Scripting

Finding all files based on pattern

Hi All, I need to find all files in a directory which are containing specific pattern. Thing is that file name should not consider if pattern is only in commented area. all contents which are under /* */ are commented all lines which are starting with -- or if -- is a part of some sentence... (13 Replies)
Discussion started by: Lakshman_Gupta
13 Replies

3. Shell Programming and Scripting

Moving old files based on pattern

Hi all I am trying to loop through a directory of files using a given search pattern. some of the files will be duplicated due to the pattern, but of the duplicate files i wanted to move the older files to another location. Is there any straightforward way of doing this ? One of ways I... (1 Reply)
Discussion started by: sthapa
1 Replies

4. UNIX for Dummies Questions & Answers

List only files based on a pattern

Hi Gurus, I need to list only the files with out certain extension. For eg from the following list of files: I need to only list: Thanks Shash (7 Replies)
Discussion started by: shash
7 Replies

5. Shell Programming and Scripting

Copying files based on a pattern

Hi All, I need to find and list the last 5 days files in that exact name with "MIM" and copy to another directory. please help me in this there is around 30000 files Thanks Murali (7 Replies)
Discussion started by: 969murali@gmail
7 Replies

6. UNIX for Advanced & Expert Users

Moving multiple files based on the pattern

I want to search for a particular file name patterns and move them to a specific folder, is it possible to do it with awk or sed? (1 Reply)
Discussion started by: rudoraj
1 Replies

7. Shell Programming and Scripting

combine lines from two files based on an if statement

I'm rather new to programming, and am attempting to combine lines from 2 files in a way that is way beyond my expertise - any help would be appreciated! I need to take a file (file1) and add columns to it from another file (file2). However, a line from file2 should only be added to a given line... (3 Replies)
Discussion started by: Cheri
3 Replies

8. Shell Programming and Scripting

How to combine two files based on fields?

I have two files which are as follows: File 1: 1 abc 250 2 pqr 300 3 xyz 100 File 2: 1 abc 230 2 pqr 700 3 xyz 500 Now I need output File, File 3as: S.No Name Count1 Count2 1 abc 250 230 2 pqr 300 700 3 xyz 100 500 NOTE: (13 Replies)
Discussion started by: karumudi7
13 Replies

9. Shell Programming and Scripting

Combine the lines based on particular pattern

Hi, I've a weird problem to be solved. Assume i have a file like this: 1. <timestamp> UID: 12345 <junk> DevID: V123 2. <timestamp>DevID: V123 <junk> DuID: VP 3. ... 4. .... 5. <timestamp> UID: 789 <junk> DevID: S456 6. <timestamp>DevID: S456 <junk> DuID: VP.... 7. ..... Say if i... (3 Replies)
Discussion started by: VenkataPrasad
3 Replies

10. Shell Programming and Scripting

how to combine 2 lines in same files based on any text

hi, I want to combine two lines in same file. If the line ends with '&' it should belongs to previous line only Here i am writing example. Ex1: line 1 : return abcdefgh& line 2 : ijklmnopqr& line 3 : stuvw& line 4 : xyz output should be line 1: return abcdefghijklmnopqrstuvwxyz ... (11 Replies)
Discussion started by: spc432
11 Replies
Login or Register to Ask a Question