I have a data file that has a list of data macthing by user.
I am able to sort by user and there is multiple rows for each user.
Ideally I would like to email only the user of the files they own. Would it be best to create a seperate file by user and all rows showing the files they own?
Assuming you have the users in the 1st field:
awk '{close($1);print > $1}' file
It would be better if you posted the input file and the output you expect.
input data file
user1 file1.txt %datecreated% file_size
user1 file2.txt %datecreated% file_size
user1 file3.txt %datecreated% file_size
user2 file4.txt %datecreated% file_size
user2 file5.txt %datecreated% file_size
user3 file6.txt %datecreated% file_size
user4 file7.txt %datecreated% file_size
user4 file8.txt %datecreated% file_size
I would need a seperate data file by user and in the data file listing the files associated with them from the input file.
like
user1.txt
file1.txt %datecreated% file_size
file2.txt %datecreated% file_size
file3.txt %datecreated% file_size
awk '{close($1 ".txt");print $2,$3,$4 > $1 ".txt"}' datafile
I think close() needs nawk.
awk -F\ \ '{f=$1 ".txt";close(f);sub($1FS,x);print >> f}' file
awk --version
awk version 20070501 (FreeBSD)
same for
awk --version
GNU Awk 3.1.3
Copyright (C) 1989, 1991-2003 Free Software Foundation.
i could not get the close statement to work. I decided to create a reference file for now.
printed the user column and removed duplicates to file userlist.txt
created script to read per line from userlist.txt and grep inputdata.txt into body of email
if there is a will there is a way. I know there is a more efficient way but i will search and tweak at my leisure
So just remove the close...and Franklin52's awk script will work.
awk '{print $2,$3,$4 > $1 ".txt"}' file
This may break if it goes over the system limit for the maximum number of open files.