Read multiple text files and copy data to csv


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Read multiple text files and copy data to csv
# 8  
Old 03-31-2016
Not clear. Which of your requirements is not fulfilled by Scrutinizer's proposal in post#2 applied to the entire directory tree? Please be aware that you did not specify any means/conditions/logics to categorize by department.
# 9  
Old 03-31-2016
Hi
Code:
awk '{print FILENAME,$2,$4,$6}' FS=':|\n' OFS=, RS= file*.txt

would only search files in the root directory. is there a way to search subfolders?
many thanks

Last edited by RudiC; 03-31-2016 at 09:01 AM.. Reason: added code tags (again)
# 10  
Old 03-31-2016
awk allows for quite a long input file list, so try
- adding */file*.txt and further down the tree
- using a command substitution like "$(find . -type f)"

Should system limits like LINE_MAX be exceeded, you need to run the awk script on several split input streams.

Last edited by RudiC; 03-31-2016 at 11:21 AM.. Reason: inserted missing double quote
This User Gave Thanks to RudiC For This Post:
# 11  
Old 03-31-2016
To elaborate on what RudiC mentioned, you can try:
Code:
find some_dir -type f -name '*.audio' -exec awk '{print FILENAME,$2,$4,$6}' FS=':|\n' OFS=, RS= {} + > outfile

This User Gave Thanks to Scrutinizer For This Post:
# 12  
Old 03-31-2016
Hi,

i had a look on the actual server and found some issues

the files dont always contain the same info.

for example, these 2 files.
one got destination but doesnt have pc name

Filename1
Code:
IP address=192.168.10.25
PC name=RecSrv
UTC begin=20150729T075150.991582
UTC end=20150729T075234.659672
destination IP address=192.168.11.1
duration (ms)=43668
local begin=20150729T085150.991582
local end=20150729T085234.659672
source IP address=192.168.11.254

Filename2
Code:
destination=D:/recording/20150729/filename2.audio
UTC begin=20150729T075150.991582
UTC end=20150729T075234.659672
destination IP address=192.168.11.1
duration (ms)=43668
local begin=20150729T085150.991582
local end=20150729T085234.659672
source IP address=192.168.11.254
actual extension=12345
original called party=08865412596
original calling party=12345

so i need awk to search for all these lines

Code:
IP address=
PC name=
destination=
UTC begin=
UTC end=
destination IP address=
duration (ms)=
local begin=
local end=
source IP address=
actual extension=
original called party=
original calling party=

and put result in a csv like this. If there is data, it would just put a blank like ,,

output.csv
Code:
FILENAME,IP address,PC name,destination,UTC begin,UTC end,destination IP address,duration (ms),local begin,local end,source IP address,actual extension,original called party,original calling party
D:/recording/20150729/filename1.audio,192.168.10.25,RecSrv,,20150729T075150.991582,20150729T075234.659672,192.168.11.1,43668,20150729T085150.991582,20150729T085234.659672,192.168.11.254,,,
D:/recording/20150729/filename2.audio,,D:/recording/20150729/filename2.audio,20150729T075150.991582,20150729T075234.659672,192.168.11.1,43668,20150729T085150.991582,20150729T085234.659672,192.168.11.254,12345,08865412596,12345

Do you think it's possible?

thanks

Last edited by RudiC; 03-31-2016 at 11:41 AM.. Reason: code tags (again)
# 13  
Old 03-31-2016
Please use code tags as required by forum rules!

Maybe one of the solutions in this thread (from the bottom margin of this page) can put you in the right direction (or even solve after some adaption)?
# 14  
Old 03-31-2016
Please, you cannot keep changing your input file specification and also your requirements in every post. Do not waste the forum members' valuable time and next time please get your specifications right in post #1.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Generate files and use csv data to replace multiple variables in a template

I have a source csv file consists of first field as variable name, and the rest are site-specific information (converted from excel file, where site -specific values in columns). I am trying to create a file for every site using a template and replace the multiple variables with values from the... (3 Replies)
Discussion started by: apalex
3 Replies

2. UNIX for Beginners Questions & Answers

Copy data at specified location from multiple files

Hello everyone, Im super new to coding but increasingly in need of it at work. Im have task stacked because of this problems, that I cannot figure out how to solve looking on the internet after trying many many things that looked similar to me. I have multiple data files of the form (see below).... (2 Replies)
Discussion started by: Xfiles_fan
2 Replies

3. Shell Programming and Scripting

In PErl script: need to read the data one file and generate multiple files based on the data

We have the data looks like below in a log file. I want to generat files based on the string between two hash(#) symbol like below Source: #ext1#test1.tale2 drop #ext1#test11.tale21 drop #ext1#test123.tale21 drop #ext2#test1.tale21 drop #ext2#test12.tale21 drop #ext3#test11.tale21 drop... (5 Replies)
Discussion started by: Sanjeev G
5 Replies

4. Shell Programming and Scripting

Read csv file, convert the data and make one text file in UNIX shell scripting

I have input data looks like this which is a part of a csv file 7,1265,76548,"0102:04" 8,1266,76545,"0112:04" I need to make the output data should look like this and the output data will be part of text file: 7|1265000 |7654899 |A| 8|12660000 |76545999 |B| The logic behind the... (6 Replies)
Discussion started by: RJG
6 Replies

5. UNIX for Beginners Questions & Answers

awk GSUB read field values from multiple text files

My program run without error. The problem I am having. The program isn't outputting field values with the column headers to file.txt. Each of the column headers in file.txt has no data. MEMSIZE SECOND SASFoundation Filename The output results in file.txt should show: ... (1 Reply)
Discussion started by: dellanicholson
1 Replies

6. Shell Programming and Scripting

Extracting data from specific rows and columns from multiple csv files

I have a series of csv files in the following format eg file1 Experiment Name,XYZ_07/28/15, Specimen Name,Specimen_001, Tube Name, Control, Record Date,7/28/2015 14:50, $OP,XYZYZ, GUID,abc, Population,#Events,%Parent All Events,10500, P1,10071,95.9 Early Apoptosis,1113,11.1 Late... (6 Replies)
Discussion started by: pawannoel
6 Replies

7. UNIX for Dummies Questions & Answers

Need help combining txt files w/ multiple lines into csv single cell - also need data merge

:confused:Hello -- i just joined the forums. I am a complete noob -- only about 1 week into learning how to program anything... and starting with linux. I am working in Linux terminal. I have a folder with a bunch of txt files. Each file has several lines of html code. I want to combine... (2 Replies)
Discussion started by: jetsetter
2 Replies

8. Shell Programming and Scripting

Read multiple files, parse data and append to a file

Hi..Can anyone suggest a simple way of achieving this. I have several files which ends with extension .vcf . I will give example with two files In the below files, we are interested in File 1: 38 107 C 3 T 6 C/T 38 241 C 4 T 5 C/T 38 247 T 4 C 5 T/C 38 259 T 3 C 6 T/C... (8 Replies)
Discussion started by: empyrean
8 Replies

9. Shell Programming and Scripting

Combine Multiple text or csv files column-wise

Hi All I am trying to combine columns from multiple text files into a single file using paste command but the record length being unequal in the different files the data is running over to the closest empty cell on the left. Please see below. What can i do to resolve this ? File 1 File... (15 Replies)
Discussion started by: venky_ibm
15 Replies

10. Shell Programming and Scripting

Read the data from multiple files and sum the value

Hi all, I have a requirement where i have to read multiple files using Shell Script in Korn Shell. each file will have the 3rd line as the amount field, i have to read this amount field and sum it for all the files. any idea on how to achieve this?? (i think i can achieve it using a loop,... (9 Replies)
Discussion started by: nvuradi
9 Replies
Login or Register to Ask a Question