Bash script - integrate two files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash script - integrate two files
# 1  
Old 01-16-2009
Bash script - integrate two files

I wrote script in bash which generates this report "users.csv":
Quote:
@admin;;
user1;yes;
user2;yes;
user3;yes;
@develop;;
user4;no;
user5;yes;
user6;no;
user7;no;
@progs;;
user8;no;
user9;no;
...
I wrote script in bash which generates this report "groups.csv"
Quote:
@admin;path1;12;
user9;path10;1;
@admin;path2;12;
@develop;path3;12;
@develop;path4;1;
@progs;path5;1;
@progs;path6;1;
@progs;path7;1;
@progs;path8;1;
...
I want to integate two reports: "users.csv" and "groups.csv".
I want like so that "result.csv":
Quote:
@admin;path1;12;;;
@admin;path2;12;;;
user1;@admin;yes;12;
user2;@admin;yes;12;
user3;@admin;yes;12;
@develop;path3;12;;;
@develop;path4;1;;;
user4;@develop;no;12 1;
user5;@develop;yes;12 1;
user6;@develop;no;12 1;
user7;@develop;no;12 1;
@progs;path5;1;;;
@progs;path6;1;;;
@progs;path7;1;;;
@progs;path8;1;;;
user8;@progs;no;1;
user9;@progs;no;1;
Thx
# 2  
Old 01-16-2009
Question Do not understand the rules

By what rules are you integrating those two files?
At least to me, it is not obvious how you are ordering your records.
# 3  
Old 01-17-2009
Quote:
Originally Posted by patrykxes
I wrote script in bash which generates this report "users.csv":
I wrote script in bash which generates this report "groups.csv"

I want to integate two reports: "users.csv" and "groups.csv".
I want like so that "result.csv":

I would use the original data to create the format you want rather than use an intermediate format.

Alternatively, create intermediate files in a format that will be easier to work with.
# 4  
Old 01-19-2009
Hi
users.csv - the first file represents the users from the following groups: @admin, @develop, @progs

groups.csv - the second file represents the groups with the paths and access rights 1 - r, 12 - rw. User9 belongs to group @progs.

The purpose of file result.csv is to present groups with certain paths and rights to paths (12 - rw, 1 - r), for example, @admin;path1;12;;; and users belonging to different groups including the rights of those groups (12 - rw, 1 - r), eg user1;@admin;yes;12;

group @develop has path3, path4, which have 12 oraz 1, respectively, user4 belongs to THIS @develop group and has ALSO rights 12 and 1

Help me please.
# 5  
Old 01-19-2009
Hi patrykxes,

You'll have to be more clearer with the rules on how integrate the 2 files. As of now, I cannot see any clear relationships. Well, I thought I did but then it wasn't. It happened a lot of times and now I have a headache Smilie Smilie
# 6  
Old 01-19-2009
I use this script (awk):
Quote:
END {
if (n > c) for (i=c; i<=n; i++)
print ";;" t[i]
}
NR == FNR {
k = $1; sub(/[^;]*; */, "")
s[k] = s[k] ? s[k] SUBSEP $0: $0
next
}
/^@/ && $1 in s {
if (n > c) for (i=c; i<=n; i++)
print ";;" t[i]
n = split(s[$1], t, SUBSEP)
c = 0
}
{ print $0 (t[++c] ? t[c] : ";;") }
but, this script show the result:
Quote:
@admin;;path1;12;
user1;yes;path2;12;
user2;yes;;;
user3;yes;;;
@develop;path3;12;
user4;no;path4;1;
user5;yes;;;
user6;no;;;
user7;no;;;
@progs;path5;1;
user8;no;path6;1;
user9;no;path10;1;
;;path7;1;
;;path8;1;
...
this result above is bad.

I want to integate (first post) two reports: "users.csv" and "groups.csv".
I want like so that "result.csv":
This result is good.
Quote:
@admin;path1;12;;;
@admin;path2;12;;;
user1;@admin;yes;12;
user2;@admin;yes;12;
user3;@admin;yes;12;
@develop;path3;12;;;
@develop;path4;1;;;
user4;@develop;no;12 1;
user5;@develop;yes;12 1;
user6;@develop;no;12 1;
user7;@develop;no;12 1;
@progs;path5;1;;;
@progs;path6;1;;;
@progs;path7;1;;;
@progs;path8;1;;;
user8;@progs;no;1;
user9;@progs;no;1;
...
Please.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to integrate all the systemctl commands into a shell script to verify any daemon/agent service?

Hi, Can we integrate all the systemctl command into a shell script to verify any service with all the options of systemctl if service integrate with the operating system service management tools to deliver their functionality. sudo systemctl start <service_name> sudo systemctl stop... (1 Reply)
Discussion started by: Mannu2525
1 Replies

2. Web Development

Help to integrate Shell script with PHP

I have a shell script which takes user name and server name from the user and check the authentication type on that server like LDAP or VAS or local. It also provides various other info also such as owner of the ID and etc. I need this script to work on the browser where user can directly input... (2 Replies)
Discussion started by: Bhuwan Nazkani
2 Replies

3. Shell Programming and Scripting

Bash script for check files

I created this script for check whether specific files exist or not in the given location. but when I run this its always showing Failed - Flag_lms_device_info_20160628.txt do not exist Failed - Flag_lms_weekly_usage_info_20160628.txt do not exist but both files are existing. appreciate help... (2 Replies)
Discussion started by: lfreez
2 Replies

4. Shell Programming and Scripting

Renumbering files bash script

I am new to the world of Linux scripting, and would like to make the following 2 scripts: I have 67 files named Alk-0001.txt to Alk-0067.txt I would like them to be numbered Alk-002.txt to Alk-0134.txt eg Alk-0001.txt > Alk-0002.txt Alk-0002.txt > Alk-0004.txt Alk-0003.txt > Alk-0006.txt ... (3 Replies)
Discussion started by: tollyboy_uk
3 Replies

5. Shell Programming and Scripting

Bash script deleting my files, and editing files in subdirectories question

#!/bin/bash # name=$1 type=$2 number=1 for file in ./** do if then filenumber=00$number elif then filenumber=0$number fi tempname="$name""$filenumber"."$type" if (4 Replies)
Discussion started by: TheGreatGizmo
4 Replies

6. UNIX for Dummies Questions & Answers

Bash script to sort files

I've got a disorganized list of items and quantities for each. I've been using a combination of grep and sort to find out how much to buy of each item. I'm tired of having to constantly using these commands so I've been trying to write a shell script to make it easier, but I can't figure out how... (3 Replies)
Discussion started by: PTcharger
3 Replies

7. Shell Programming and Scripting

bash script to copy files

hey everyone, new here i have arch setup and i am using smbnetfs to mount some windows shares in /mnt/smbnet what i want to do is copy files from my home dir to a dir in /mnt/smbnet but i also need it to remove files if i have deleted them from my home dir seems that cp would be the... (8 Replies)
Discussion started by: dodgefan67
8 Replies

8. Shell Programming and Scripting

Again integrate files - bash script

I wrote script in bash which generates this report "users.csv": I wrote script in bash which generates this report "groups.csv" I want to integate two reports: "users.csv" and "groups.csv". I want like so that "result.csv": (2 Replies)
Discussion started by: patrykxes
2 Replies

9. Shell Programming and Scripting

Renaming files in a bash script

I'm doing a short batch script to compile po files producing output binary mo files. The compilation command is: msgfmt -o file.mo file.po so in order to compile I am appending .mo to the varible in a loop. It goes something like this: for i in `find . -name "*.po"` do echo... (2 Replies)
Discussion started by: Breen
2 Replies
Login or Register to Ask a Question