Concatenating two files in required format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Concatenating two files in required format
# 1  
Old 02-21-2013
Concatenating two files in required format

Firstly one of my mysql queries will yeild following output

Code:
+-------+---------------------+-------------------+----------------------------------------------------------------------------+
| ID    | PLATFORM            | SORT_NAME         | DESCRIPTION                                                                |
+-------+---------------------+-------------------+----------------------------------------------------------------------------+
| 11312 | ccm113              | LINUX             |                                                                            |
+-------+---------------------+-------------------+----------------------------------------------------------------------------+

when i redirect it to one file, the tabluar format is not retained. Any idea how to retain the tabluar format even after retaining?? (or to provide a custom tabular format while redirecting?)

as of now i redirected it to one file it comes in below format witth mismatched spacing and indentation


Code:
cat output1.txt
ID      PLATFORM        SORT_NAME       DESCRIPTION
11312   ccm113  LINUX

i have output of another script, its output is for respective ID of above mysql query, is as below

Code:
cat output2.txt
Availability: GREEN
Availability: RED
Availability: GREEN
Availability: RED
Availability: RED

now i want to merge output2.txt with output1.txt as additional column and still retain initial column or provide similiar column of mysql output.

is it feasible? any help is deeply appreciated.. thanks


PS: i want to achiveve finial output as below in a file

[CODE]+-------+---------------------+-------------------+----------------------------------------------------------------------------+--------------+
| ID | PLATFORM | SORT_NAME | DESCRIPTION | AVAILABILITY |
+-------+---------------------+-------------------+----------------------------------------------------------------------------+--------------+
| 11312 | ccm113 | LINUX | | GREEN |

Last edited by vivek d r; 03-20-2013 at 11:40 AM..
# 2  
Old 02-21-2013
Put a header line on file 2 or remove from file 1 and 'paste'.
# 3  
Old 02-24-2013
OK...well here is one way...

1) cat [your_first_mysqloutput_file] | sed 's/\t/","/g;s/^/"/;s/$/"/;s/\n//g' > your_first_new_file.csv
2) Do the same to the file you want to append to the first creating your_second_new_file.csv
3) cat your_second_new_file.csv >> your_first_new_file.csv
3) cat your_first_new_file.csv | sed 's/","/\t/g' > your_result
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help required in printing in specific format

Hi All, I 'm matching two files based on the first 2 columns and then populate other fields along with subtraction of few fields. I have managed to get the output. However, is there a easier way in formatting the output as shown below instead of using additional printf for getting fixed width... (4 Replies)
Discussion started by: shash
4 Replies

2. UNIX for Dummies Questions & Answers

help required in converting a file format

My file format: -------------------------------------------------- Complete Consistency Check Valid Area : VALID:VALID Started by : esanwad Started at : Thu Dec 11 16:04:46 2014 CNA version : R21H04_EC08 Check range : AREA VALID/VALID ... (4 Replies)
Discussion started by: Gautam Banerjee
4 Replies

3. Shell Programming and Scripting

Need help to format one txt file to required format

Hello Everyone, I have one source file which is genarated by SAP in different format(Which I've never seen). I need to convert that file to required format and I need to read this target file from Datastage to use this in my Jobs. So I do not have any other options except to use Unix script to... (4 Replies)
Discussion started by: Prathyu
4 Replies

4. Shell Programming and Scripting

Not able to convert the second column to required format

I have this file 103,7243534512111,NiaC1-02 105,720412845543550,NiaC2-00 105,720439254543351,NiaC200 105,720445724354315,Nia100 105,72044770454398,Nia100 105,720484154334546,Nia616 i want in this format insert into aildump values(103,'7243534512111','NiaC1-02'); I'm able to... (3 Replies)
Discussion started by: nikhil jain
3 Replies

5. UNIX for Dummies Questions & Answers

awk printf in required format

Hi my awk variable $0 contains the below data Input file 000001 The Data 000002* The line 2 000003* The line3 output file Req 000001* The Data 000002** The line 2 000003** The line3 one * at column seven needs to be appended to the input lines, (5 Replies)
Discussion started by: rakeshkumar
5 Replies

6. UNIX for Dummies Questions & Answers

Concatenating Text Files

Hi, I have 30 text files on UNIX that I need to concatenate and create one big file. Could anyone provide me with a solution (if one exist)? I need the answer asap (today). Thanks a lot. Denis (5 Replies)
Discussion started by: 222001459
5 Replies

7. Shell Programming and Scripting

Concatenating two files

HI I need to concatenate two files which are having headers. the result file should contain only the header from first file only and the header in second file have to be skipped. file1: name age sriram 23 file2 name age prabu 25 result file should be name age sriram 23 prabu ... (6 Replies)
Discussion started by: Sriramprabu
6 Replies

8. Shell Programming and Scripting

negatively concatenating files

That subject might sound weird. What I have is two files. One looks like: rf17 pts/59 Jul 10 08:43 (10.72.11.22) 27718 pts/59 0:00 b rf17 pts/3 Jul 10 10:03 (10.72.11.22) 32278 pts/3 1:43 b rf58 pts/29 Jul 10 10:09 (10.72.11.51) 44220 pts/29 0:06 b rf58 pts/61 Jul 10 08:45 (10.72.11.51)... (2 Replies)
Discussion started by: raidzero
2 Replies

9. UNIX for Dummies Questions & Answers

concatenating x files into a one...

... i have 4 files to concatenate but in a certain order and i wanted to do it in a shorter one line command , if possible ! 4 files : file , file0 , file1 and file2 file1 into file2 file0 into the result file into the result thanks in advance Christian (1 Reply)
Discussion started by: Nicol
1 Replies
Login or Register to Ask a Question