Sponsored Content
Top Forums Shell Programming and Scripting Create csv from four disparate files Post 303035147 by RecoveryOne on Wednesday 15th of May 2019 10:34:03 AM
Old 05-15-2019
Quote:
Originally Posted by k_manimuthu
Try the below codes and integrate into your script.
Code:
#!/bin/sh
#By default array string tokenizer considered as space, But we need entire line. 
# So whitespace replaced as _SPACE_
F1=( `cat host1.account.out | sed 's/ /_SPACE_/g'  ` )
F2=( `cat host1.max.out | sed  's/ /_SPACE_/g'  ` )
F3=( `cat host1.pwd.out  | sed  's/ /_SPACE_/g'  ` )
F4=( `cat host1.standard.out | sed  's/ /_SPACE_/g'  ` )
h='host1'
i=0
# get maximum number of lines from the above files and iterate here
while [ $i -lt ${#F4[@]} ]
do
        echo "$h",${F1[$i]},${F2[$i]},${F3[$i]},${F4[$i]} |  tr -d '\r' | sed -E 's/(_SPACE_)+/ /g'
        i=`expr $i + 1`
done

OH, et max lines and iterate! I like! YES!!!!





Quote:
Originally Posted by RudiC
How about
Code:
IFS=. read H REST <<EOF
$(echo *.out)
EOF
echo "host,accounts,max,pwd,standard"; echo $H | paste -d, - *.out
host,accounts,max,pwd,standard
host1,root,9,abc pwd=,standard:
,user1,,,        user = true
,user2,,,        expires = 0
,,,,        core_path = on
 ,,,,        default_roles =

Pipe result through sed 's/, \+/,/' to get rid of the residual spaces from *standard*.out.

I seem to be having a hard time getting this to process multiple files from multiple host. If there's only host1.*.out files its fine, as soon as host2.*.out files exist it gets all funky.



Example of there's host2.*.out files:
Code:
host,accounts,max,pwd,standard
host1,root,9,abc pwd=,standard:,root,9,abc pwd=,standard:
,user1,,,        user = true,user1,,,        user = true
,user2,,,       expires = 0,user2,,,    expires = 0
,,,,    core_path = on,,,,      core_path = on
,,,,    default_roles =,,,,     default_roles =


Thank you both!
 

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
rwho(1) 						      General Commands Manual							   rwho(1)

NAME
rwho - Shows which users are logged into hosts on the local network. SYNOPSIS
rwho [-a] rwho [-a] [users] OPTIONS
Includes all users. Without this option, users whose sessions are idle an hour or more are not included in the report. DESCRIPTION
The rwho command displays the username, hostname, and start date and time of each session for everyone on the local network who is cur- rently logged in to a host running the rwhod daemon. If one or more user names are specified, only the status of those users whose names are listed appears on the screen. If a user has not typed anything for at least 3 minutes, rwho reports the idle time as a number of minutes in the last column. After an hour of inactivity, a user is not included unless the -a option is specified. Because this command displays a lot of output, use this command with caution if the local network has a large number of users. Status information is broadcast once every 3 minutes by each network host running the rwhod daemon. Any activity (such as a user logging on or off) that takes place between broadcasts is not reflected until the next broadcast. EXAMPLES
To get a report of all users currently logged into hosts on the local network, enter: $ rwho bob host2:pts5 Nov 17 06:30 :20 bob host7:console Nov 17 06:25 :25 franz host1:pts0 Nov 17 11:20 :51 franz host1:pts8 Nov 16 15:33 :42 franz host4:console Nov 17 16:32 pietro host1:console Nov 17 13:14 :31 pietro host1:pts7 Nov 17 13:15 :47 server host2:console Nov 17 06:58 :20 luis host2:pts6 Nov 17 09:22 FILES
Indicates data files received from remote rwhod daemons. SEE ALSO
Commands: ruptime(1), rwhod(8) rwho(1)
All times are GMT -4. The time now is 06:14 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy