Sponsored Content
Top Forums Shell Programming and Scripting Create csv from four disparate files Post 303035114 by RecoveryOne on Tuesday 14th of May 2019 07:24:30 PM
Old 05-14-2019
Create csv from four disparate files

Hey everyone,
So newbie when it comes to scripting and lurked on these pages for some time as I slowly learn. I'd like to thank everyone for taking the time to share their knowledge, and would like to think I've picked up a something from these forums.
What I'm trying to do, is create a csv from four disparate files containing data.


Here's my current script. Its meant to have multiple files from multiple hosts, hence the loop.
I am limited to the tool set on AIX, and cannot use any GNU tools.

Code:
#!/bin/ksh
set -A allHosts $(ls -1 *.out | awk -F\. '{print $1}' | sort -u | uniq)
echo "host,accounts,max,pwd,standard"
for h in ${allHosts[@]}; do
        col1=$(cat ./${h}.account.out)
        col2=$(cat ./${h}.max.out)
        col3=$(cat ./${h}.pwd.out)
        col4=$(cat ./${h}.standard.out |  sed -e 's/^[ \t]*//')
        echo "${h}","${col1}","${col2}","${col3}","${col4}"
        unset col1
        unset names
        unset col2
        unset col3
        unset col4
done

File are setup like:
host1.max.out
Code:
9

host1.account.out
Code:
root
user1
user2

host1.pwd.out
Code:
abc pwd=

host1.standard.out
Code:
standard:
        user = true
        expires = 0
        core_path = on
        default_roles =

Results I'm current receiving:
Code:
host,accounts,max,pwd,standard
host1,root
user1
user2,9,abc pwd=,standard:
user = true
expires = 0
core_path = on
default_roles =

Desired output:
Code:
host,account,max,pwd,standard
host1,root,9,abc pwd=,standard:
,user1,,,user = true
,user2,,,expires = 0
,,,,core_path = on
 ,,,,default_roles =


Thank you for your time and my apologies if this has been asked before, but my searching abilities has failed me.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare two csv files by two colums and create third file combining data from them.

I've got two large csv text table files with different number of columns each. I have to compare them based on first two columns and create resulting file that would in case of matched first two columns include all values from first one and all values (except first two colums) from second one. I... (5 Replies)
Discussion started by: agb2008
5 Replies

2. Shell Programming and Scripting

Merging files to create CSV file

Hi, I have different files of the same type, as: Time: 100 snr: 88 perf: 10 other: 222 Each of these files are created periodically. What I need to do is to merge all of them into one but having the following form: (2 Replies)
Discussion started by: Ravendark
2 Replies

3. Shell Programming and Scripting

How to create a CSV File by reading fields from separate files

SHELL SCRIPT Hi, I have 3 separate files within a folder. Every File contains data in a single column like File1 contains data mayank sushant dheeraj File2 contains DSA_AT MG_AT FLAT_09 File3 contains data 123123 232323 (2 Replies)
Discussion started by: mayanksargoch
2 Replies

4. Shell Programming and Scripting

Merge CSV files and create a column with the filename from the original file

Hello everyone!! I am not completely new to shell script but I havent been able to find the answer to my problem and I'm sure there are some smart brains here up for the challenge :D. I have several CSV files that I need to combine into one, but I also need to know where each row came from.... (7 Replies)
Discussion started by: fransanchezoria
7 Replies

5. UNIX for Dummies Questions & Answers

How to create a .csv file from 2 different .txt files?

Hi, I need to create a .csv file from information that i have in two different tab delimited .txt file. I just want to select some of the columns of each .txt file and paste them into a .cvs file. My files look like: File 1 transcript_id Seq. Description Seq. Length ... (2 Replies)
Discussion started by: alisrpp
2 Replies

6. Shell Programming and Scripting

Comparing Select Columns from two CSV files in UNIX and create a third file based on comparision

Hi , I want to compare first 3 columns of File A and File B and create a new file File C which will have all rows from File B and will include rows that are present in File A and not in File B based on First 3 column comparison. Thanks in advance for your help. File A A,B,C,45,46... (2 Replies)
Discussion started by: ady_koolz
2 Replies

7. Shell Programming and Scripting

How to create or convert to pdf files from csv files using shell script?

Hi, Can anyone help me how to convert a .csv file to a .pdf file using shell script Thanks (2 Replies)
Discussion started by: ssk250
2 Replies

8. Shell Programming and Scripting

Match columns from two csv files and update field in one of the csv file

Hi, I have a file of csv data, which looks like this: file1: 1AA,LGV_PONCEY_LES_ATHEE,1,\N,1,00020460E1,0,\N,\N,\N,\N,2,00.22335321,0.00466628 2BB,LES_POUGES_ASF,\N,200,200,00006298G1,0,\N,\N,\N,\N,1,00.30887539,0.00050312... (10 Replies)
Discussion started by: djoseph
10 Replies

9. Shell Programming and Scripting

Compare 2 files of csv file and match column data and create a new csv file of them

Hi, I am newbie in shell script. I need your help to solve my problem. Firstly, I have 2 files of csv and i want to compare of the contents then the output will be written in a new csv file. File1: SourceFile,DateTimeOriginal /home/intannf/foto/IMG_0713.JPG,2015:02:17 11:14:07... (8 Replies)
Discussion started by: refrain
8 Replies

10. Shell Programming and Scripting

Matching two fields in two csv files, create new file and append match

I am trying to parse two csv files and make a match in one column then print the entire file to a new file and append an additional column that gives description from the match to the new file. If a match is not made, I would like to add "NA" to the end of the file Command that Ive been using... (6 Replies)
Discussion started by: dis0wned
6 Replies
All times are GMT -4. The time now is 03:55 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy