Combine Multiple Files into Single One File One after other


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Combine Multiple Files into Single One File One after other
# 1  
Old 10-30-2012
Combine Multiple Files into Single One File One after other

I am trying to combine 4 .dat files into one single Output file
Inputs are:- file123.dat, file256.dat, file378.dat & file490

Expected Output:-
Code:
FileName=file1
{text from file1}
EOF
{blank line}
FileName=file2
{text from file2}
EOF
{blank line}
FileName=file3
{text from file3}
EOF
{blank line}
FileName=file4
{text from file4}
EOF

I tried $ cat file123.dat file256.dat file378.dat file490.dat > Result.dat
But this one messed up first line from all files and not giving required expected output.
Thanks much.
-LanceSunny

Last edited by lancesunny; 10-30-2012 at 04:41 PM..
# 2  
Old 10-30-2012
Try:
Code:
for i in file123.dat file256.dat file378.dat file490.dat; do 
  echo "FileName=$i"
  cat "$i"
  echo "EOF"
  echo
done > Result.dat

# 3  
Old 10-30-2012
Thanks bartus11.
But your solution is not inserting Blank Line after end of each file and combining last line of current file with first line from next file.

Last edited by lancesunny; 10-30-2012 at 04:52 PM..
# 4  
Old 10-30-2012
This is the output I'm getting for those sample files:
file a:
Code:
a
a
a

file b:
Code:
b
b
b

Result:
Code:
FileName=a
a
a
a
EOF

FileName=b
b
b
b
EOF

Are you getting different output? Or should the output be formatted in an other way?
This User Gave Thanks to bartus11 For This Post:
# 5  
Old 10-30-2012
Thanks bartus11.
Your code worked Fine.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Split a single file into multiple files based on a value.

Hi All, I have the sales_data.csv file in the directory as below. SDDCCR; SOM ; MD6546474777 ;05-JAN-16 ABC ; KIRAN ; CB789 ;04-JAN-16 ABC ; RAMANA; KS566767477747 ;06-JAN-16 ABC ; KAMESH; A33535335 ;04-JAN-16 SDDCCR; DINESH; GD6674474747 ;08-JAN-16... (4 Replies)
Discussion started by: ROCK_PLSQL
4 Replies

2. Shell Programming and Scripting

Splitting a single file to multiple files

Hi Friends , Please guide me with the code to extract multiple files from one file . The File Looks like ( Suppose a file has 2 tables list ,column length may vary ) H..- > File Header.... H....- >Table 1 Header.... D....- > Table 1 Data.... T....- >Table 1 Trailer.... H..-> Table 2... (1 Reply)
Discussion started by: AspiringD
1 Replies

3. Shell Programming and Scripting

Combine multiple lines into single line

Hi All , I have a file with below data # User@Host: xyz @ # Query_time: t1 Lock_time: t2 Rows_sent: n1 Rows_examined: n2 SET timestamp=1396852200; select count(1) from table; # Time: 140406 23:30:01 # User@Host: abc @ # Query_time: t1 Lock_time: t2 Rows_sent: n1 Rows_examined:... (6 Replies)
Discussion started by: rakesh_411
6 Replies

4. Shell Programming and Scripting

Compare multiple files, identify common records and combine unique values into one file

Good morning all, I have a problem that is one step beyond a standard awk compare. I would like to compare three files which have several thousand records against a fourth file. All of them have a value in each row that is identical, and one value in each of those rows which may be duplicated... (1 Reply)
Discussion started by: nashton
1 Replies

5. Shell Programming and Scripting

how to find first files in a directory and combine them as a single file?

i have below list of files in a directory. /root/admin/files/file1.txt /root/admin/files/file2.txt /root/admin/files/file3.txt /root/admin/files/pattern.txt /root/admin/files/server.txt i need combine the above text files in the below sequence, file1.txt, pattern.txt,server.txt =>... (8 Replies)
Discussion started by: vel4ever
8 Replies

6. Emergency UNIX and Linux Support

Combine multiple Files into one big file

Hi Ppl, I have a requirement like i will be getting files of huge size daily and if the file size is so huge ,the files will be split into many parts and sent.The first file will have the header details followed by detail records and the consecutive files will have detail records and the last... (11 Replies)
Discussion started by: ganesh_248
11 Replies

7. Shell Programming and Scripting

Merging information from multiple files to a single file

Hello, I am new to unix and need help with a problem. I have 2 files each containing multiple columns of information ie; File 1 : A B C D E 1 2 3 4 5 File 2 : F G 6 7 I would like to merge the information from File 2 to File 1 so that the data reads as follows; File 1: A... (4 Replies)
Discussion started by: crunchie
4 Replies

8. Shell Programming and Scripting

Combine multiple lines in single line

This is related to one of my previous post but now with a slight difference: I need the "Updated:" to be in one line as well as the "Information:" on one line as well. These are in multiple lines right now as seen below. These can have 2 or more lines that needs to be in one line. System name:... (8 Replies)
Discussion started by: The One
8 Replies

9. UNIX for Dummies Questions & Answers

Combine multiple files with common string into one new file.

I need to compile a large amount of data with a common string from individual text files throughout many directories. An example data file is below. I want to search for the following string, "cc_sectors_1" and combine all the data from each file which contains this string, into one new... (2 Replies)
Discussion started by: GradStudent2010
2 Replies
Login or Register to Ask a Question