Concatenating contents of a file with members in a directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Concatenating contents of a file with members in a directory
# 1  
Old 09-25-2012
Concatenating contents of a file with members in a directory

Hi,

I have a unix file with the below structure -

Code:
CustId1   CustName1 CustPhn1  /u/home/xmldata/A000001
CustId2   CustName2 CustPhn2  /u/home/xmldata/A000002
CustId3   CustName3 CustPhn3  /u/home/xmldata/A000003

Then I have another unix directory /u/home/xmldata
This directory has below members which contain 1 XML record. Record length of XML is 80K.
Code:
A000001
A000002
A000003

My requirement is to concatenate 1st 3 fields of records in the file with the content of member name specified in 4th field.

For example, output should look like this -
Code:
CustId1   CustName1 CustPhn1  <XML record present in A000001>
CustId2   CustName2 CustPhn2  <XML record present in A000002>
CustId3   CustName3 CustPhn3  <XML record present in A000003>

Can somebody help me out with a shell script for this. I am completely novice to UNIX as I am a Mainframe guy.

Thanks in advance!!!
Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 09-25-2012 at 02:51 PM.. Reason: code tags, please!
# 2  
Old 09-25-2012
Code:
#!/bin/ksh

while read one two three four junk
do
   echo $one $two $three $(cat ${four})
done

# 3  
Old 09-25-2012
Hi,

Thanks for your quick reply. I understand that the file we are reading will be parsed to 4 fields one two three & four. Then we are concatenating the one two three and contents of four.

Can you please help me out with the code of reading the input file and then writing the output to a output file.

Thanks again!!!
# 4  
Old 09-25-2012
ooops - missed that Smilie
Code:
#!/bin/ksh  

while read one two three four junk
do    
    echo $one $two $three $(cat ${four})
done < myInputFile > myOutputFile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Rename file in directory using contents within each file

In the below there are two generic .vcf files (genome.S1.vcf and genome.S2.vcf) in a directory. There wont always be two genaric files but I am trying to use bash to rename each of these generic files with specfic text (unique identifier) within in each .vcf. The text will always be different, but... (11 Replies)
Discussion started by: cmccabe
11 Replies

2. Shell Programming and Scripting

Concatenating many files based on a specific column contents

Dear all, I have many files(.csv) in a directory. I want to concatenate the files which have similar entries in a particular column and save into a new file like result_datetime.csv etc. One example file is like below. Sno,Step,Data1,Data2,Data3 etc. 1,0,2,3,4 2,1,3,4,5 3,2,0,1,1 ... (4 Replies)
Discussion started by: ks_reddy
4 Replies

3. Shell Programming and Scripting

concatenating similar files in a directory

Hi, I am new in unix. I have below requirement: I have two files at the same directory location File1.txt and File2.txt (just an example, real scenario we might have File2 and File3 OR File6 and File7....) File1.txt has : header1 record1 trailer1 File2.txt has: header2 record2... (4 Replies)
Discussion started by: Deepak62828r
4 Replies

4. UNIX for Dummies Questions & Answers

Help with searching for a file in a directory and copying the contents of that file in a new file

Hi guys, I am a newbie here :wall: I need a script that can search for a file in a directory and copy the contents of that file in a new file. Please help me. :confused: Thanks in advance~ (6 Replies)
Discussion started by: zel2zel
6 Replies

5. Shell Programming and Scripting

Copy contents of a directory only if a file exists

I'm looking to write a script that will check the contents of a directory, and if any files exist in that directory copy them to a temporary folder. The target files are only resident for a few seconds, so I think the script needs to be running constantly. Any pointers would be really... (3 Replies)
Discussion started by: danceofillusion
3 Replies

6. UNIX for Dummies Questions & Answers

Move contents of a directory into one file for e-mail distribution ...

Hello, Here is what I am trying to accomplish. I am going to have one directory in which there will be files of varying types (Excel, Word, PPT, and possible others), and I need to be able to be bundle however many files there are in there together in to one file to be used as an e-mail... (3 Replies)
Discussion started by: rip73
3 Replies

7. Shell Programming and Scripting

Replacing string in all instances (both filenames and file contents) in a directory

Hi, I have a set of files stored in a single directory that I use to set parameters for a physics code, and I would like to streamline the process of updating them all when I change a parameter. For instance, if the files are called A2000p300ini, A2000p300sub, A2000p300run, and the text in each... (3 Replies)
Discussion started by: BlueChris
3 Replies

8. Shell Programming and Scripting

concatenating the filenames in a directory

hi all, I have a requirement where in i have to read all the filenames based on a pattern from a directory and concatenate all these file names and write it to another file. i am using the following code to do this var1='' for filename in $_DIR/${FILE_NAME}* do if if then... (7 Replies)
Discussion started by: nvuradi
7 Replies

9. Programming

How to read and write directory or file contents in c++ ?

Dear Friends, I m beginner unix programmer. I want to know, how to read and write directory or file contents in c++ ? (3 Replies)
Discussion started by: namrata5
3 Replies

10. Shell Programming and Scripting

SED To insert Directory Contents to file

I am on a HP-UX machine I have a directory called "/u01/blobs" and the files look like this: ls -1 7398 7399 7400 I need to produce a comma delimited file with the following format: filename,location/filename i.e: 7398,/u01/blobs/7398 7399,/u01/blobs/7399 7400,/u01/blobs/7400 What... (3 Replies)
Discussion started by: NomDeGuerre
3 Replies
Login or Register to Ask a Question