create a new file from data file from a column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting create a new file from data file from a column
# 1  
Old 06-14-2011
create a new file from data file from a column

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?
# 2  
Old 06-14-2011
Assuming you have the users in the 1st field:
Code:
awk '{close($1);print > $1}' file

# 3  
Old 06-14-2011
It would be better if you posted the input file and the output you expect.
# 4  
Old 06-14-2011
input data file
Code:
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
Code:
file1.txt  %datecreated%  file_size
file2.txt  %datecreated%  file_size
file3.txt  %datecreated%  file_size

# 5  
Old 06-14-2011
Code:
awk '{close($1 ".txt");print $2,$3,$4 > $1 ".txt"}' datafile


Last edited by Franklin52; 06-14-2011 at 03:43 PM.. Reason: typo
# 6  
Old 06-14-2011
I think close() needs nawk.
# 7  
Old 06-14-2011
Code:
awk -F\ \  '{f=$1 ".txt";close(f);sub($1FS,x);print >> f}' file

awk --version
awk version 20070501 (FreeBSD)

same for
Code:
awk --version
GNU Awk 3.1.3
Copyright (C) 1989, 1991-2003 Free Software Foundation.

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

Compare 2 text file with 1 column in each file and write mismatch data to 3rd file

Hi, I need to compare 2 text files with around 60000 rows and 1 column. I need to compare these and write the mismatch data to 3rd file. File1 - file2 = file3 wc -l file1.txt 58112 wc -l file2.txt 55260 head -5 file1.txt 101214200123 101214700300 101250030067 101214100500... (10 Replies)
Discussion started by: Divya Nochiyil
10 Replies

3. Shell Programming and Scripting

create txt file form data file

File A.txt LL07 LL07_B_1 20 LL85 LL85_A_1 40 LL85 LL85_B_1 40 LL85 LL85_C_1 30 LL37 LL37_A_1 60 LL37 LL37_B_1 20 LL37 LL37_C_1 50 I want cretae diffrent tex file base of above file Should be threee text file LL07.txt LL85.txt LL37.txt Eaach text file have below data... (2 Replies)
Discussion started by: asavaliya
2 Replies

4. Shell Programming and Scripting

create txt file form data file and add some line on it

Hi Guys, I have file A.txt File A Data AK1521 AK2536 AK3164 I want create text file of all data above and write some data on each file. want Output on below folder /home/kka/out AK1521.txt Hi Welocme (3 Replies)
Discussion started by: asavaliya
3 Replies

5. Shell Programming and Scripting

Copy data form File A and Create File B

File A I have list of : ABCND1 ABCND2 ABCnd3 ABCnd4 I want file B like below Start+ S Pate=ABCND1 AAlo1 S Pate=ABCND1 Q1234 S Pate=ABCND1,P12345 (7 Replies)
Discussion started by: asavaliya
7 Replies

6. Shell Programming and Scripting

Replace column that matches specific pattern, with column data from another file

Can anyone please help with this? I have 2 files as given below. If 2nd column of file1 has pattern foo1@a, find the matching 1st column in file2 & replace 2nd column of file1 with file2's value. file1 abc_1 foo1@a .... abc_1 soo2@a ... def_2 soo2@a .... def_2 foo1@a ........ (7 Replies)
Discussion started by: prashali
7 Replies

7. Shell Programming and Scripting

How to split a data file into separate files with the file names depending upon a column's value?

Hi, I have a data file xyz.dat similar to the one given below, 2345|98|809||x|969|0 2345|98|809||y|0|537 2345|97|809||x|544|0 2345|97|809||y|0|651 9685|98|809||x|321|0 9685|98|809||y|0|357 9685|98|709||x|687|0 9685|98|709||y|0|234 2315|98|809||x|564|0 2315|98|809||y|0|537... (2 Replies)
Discussion started by: nithins007
2 Replies

8. Shell Programming and Scripting

How to cut data from file and create another file.

I have file which has more than 1000 lines. PFB file info Line 1. <SOAP-ENV:Envelope SOAP-ENV:encodingStyle="" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAPSDK1="http://www.w3.org/2001/XMLSchema" xmlns:SOAPSDK2="http://www.w3.org/2001/XMLSchema-instance"... (8 Replies)
Discussion started by: humaemo
8 Replies

9. UNIX for Dummies Questions & Answers

create data file from report file

Dear Ones, kindly help me to create a data file from the report file as shown here under( i am new one to unix KNOW BASIC COMMANDS) file:rama.prt (ist record)(3 to 4 lines of text with different filed names) Name :M.LALITHA DOB:12/11/45 DESG :JA(P) STANO:300175 ... (3 Replies)
Discussion started by: cvvsnm
3 Replies
Login or Register to Ask a Question