Shell Script to Read the given file contents into a merged one file


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Shell Script to Read the given file contents into a merged one file
# 1  
Old 05-07-2019
Shell Script to Read the given file contents into a merged one file

Like to have shell script to Read the given file contents into a merged one file with header of path+file name followed by file contents into a single output file.

While reading and merging the file contents into a single file, Like to keep the format of the source file.

Code:
/app/oracle/build_lib/wrkfldr952.0_20150614/ddl/alter_modify_keg.sql 
/app/oracle/build_lib/wrkfldr952.0_20150614/ddl/alter_modify_kim.sql
/app/oracle/build_lib/wrkfldr952.0_20150614/ddl/client_cmpmadr1.sql 
/app/oracle/build_lib/wrkfldr952.0_20150614/ddl/client_cmpmaur1.sql 
/app/oracle/build_lib/wrkfldr952.0_20150628/ddl/alter_modify_keg.sql
 /app/oracle/build_lib/wrkfldr952.0_20150628/ddl/alter_modify_kim.sql

------ Sample Output ----
1. Reading the file# /app/oracle/build_lib/wrkfldr952.0_20150614/ddl/alter_modify_keg.sql
Code:
aaa
  aaa
aa

2. Reading the file# /app/oracle/build_lib/wrkfldr952.0_20150614/ddl/alter_modify_kim.sql
Code:
bbbbbbbbb
#sssss   tttt 523


Thanks, Siva SQL


Moderator's Comments:
Mod Comment
Please wrap all code, data/files, input & output/errors in CODE tags.
It makes it far easier to read an preserves spacing for indenting or fixed-width data.

Last edited by rbatte1; 05-08-2019 at 08:37 AM..
# 2  
Old 05-07-2019
Try
Code:
for FN in /app/oracle/build_lib/wrkfldr952.0_20150614/ddl/*.sql
  do  echo  $FN
      cat "$FN";
  done;

# 3  
Old 05-07-2019
Quote:
Originally Posted by RudiC
Try
Code:
for FN in /app/oracle/build_lib/wrkfldr952.0_20150614/ddl/*.sql
  do  echo  $FN
      cat "$FN";
  done;

Thanks for the response.
However,
Using the cat the alignment of the source file is getting changed , when this is getting merged into a single file !!
# 4  
Old 05-07-2019
Difficult to believe. Why (and how) should cat change the alignment?
# 5  
Old 05-11-2019
Thanks RudiC, it solved the issue.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script (sh file) logic to compare contents of one file with another file and output to file

Shell script logic Hi I have 2 input files like with file 1 content as (file1) "BRGTEST-242" a.txt "BRGTEST-240" a.txt "BRGTEST-219" e.txt File 2 contents as fle(2) "BRGTEST-244" a.txt "BRGTEST-244" b.txt "BRGTEST-231" c.txt "BRGTEST-231" d.txt "BRGTEST-221" e.txt I want to get... (22 Replies)
Discussion started by: pottic
22 Replies

2. Shell Programming and Scripting

Script for getting the file merged

Hi, I have two files separated by bars at each line File 1 : A|4356|13456|23456 A|4356|2986|98732 A|8765|218|1432567 File 2: B|12|13456|1234567 B|11|13456|123456789 B|33|2986|98732 B|11|2986|14578965 B|8765|218|147584 Common field is third field like 13456, 2986 and 218 in both... (5 Replies)
Discussion started by: Mannu2525
5 Replies

3. Shell Programming and Scripting

Modifying contents of the file in shell script

Hello all, I have a Kconfig file that looks like something below ... ================================ menu "Application type" config GUI_TYPE_STANDARD bool "Standard Application" source "cfg/config/std.in" source... (12 Replies)
Discussion started by: anand.shah
12 Replies

4. Shell Programming and Scripting

Replace partial contents of file with contents read from other file

Hi, I am facing issue while reading data from a file in UNIX. my requirement is to compare two files and for the text pattern matching in the 1st file, replace the contents in second file by the contents of first file from start to the end and write the contents to thrid file. i am able to... (2 Replies)
Discussion started by: seeki
2 Replies

5. Shell Programming and Scripting

script to read the contents of a file and print

Hi, Need help in writing a script to read the contents of this file test Test 00a 00b 00c 00d 00e 00f where it need to read each line to give a display such as form meta from dev 00a , config=Striped; add dev 00b:00f to meta 00a Can any one help me in writing this script (2 Replies)
Discussion started by: praveen1516
2 Replies

6. Shell Programming and Scripting

shell script to compare file contents

Hello Has anyone got an example shell script that I can use to compare the contents of two files. The files should contain the same contents, eg. file1.txt apple pear grape file2.txt apple pear grape (2 Replies)
Discussion started by: deedaz
2 Replies

7. Shell Programming and Scripting

Need shell script to read two file at same time and print out in single file

Need shell script to read two file at same time and print output in single file Example I have two files 1) file1.txt 2) file2.txt File1.txt contains Aaa Bbb Ccc Ddd Eee Fff File2.txt contains Zzz Yyy Xxx (10 Replies)
Discussion started by: sreedhargouda
10 Replies

8. Shell Programming and Scripting

Shell script for converting file contents into CSV

Hi, I am new in unix, I just want to replace some values from text file according to column numbers. Like, I am having a table as given below: val1 val2 val3 val4 val5 val6 val7 val8 val9 val10 val11 val12 val13 Now i want... (5 Replies)
Discussion started by: rish_max
5 Replies

9. Shell Programming and Scripting

update file contents using shell script

Hi, I am having a file which contains as below Names(aaaa ,bbbb ,cccc ,dddd) now i want the file to be updated with new value 'eeee' as below Names(aaaa ,bbbb ,cccc ,dddd ,eeee) Is there a way to script this ? Thanks, (5 Replies)
Discussion started by: drams
5 Replies

10. Shell Programming and Scripting

search for the contents in many file and print that file using shell script

hello have a file1 H87I Y788O T347U J23U and file2 J23U U887Y I99U T556U file3 I99O J99T F557J file4 N99I T666U R55Y file5 H87I T347U file6 H77U R556Y E44T file7 Y788O K98U H8I May be using script we can use file1 to search for all the files and have the output H87I file5... (3 Replies)
Discussion started by: cdfd123
3 Replies
Login or Register to Ask a Question