Paste the files contents differently


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Paste the files contents differently
# 1  
Old 05-16-2007
Paste the files contents differently

Hello ,

I want to segregate by file contents in a much simpler format ie input file

Wednesday May 16 11:59:44 IST 2007
90376 44136 process1 pid1
90200 43208 process1 pid2
90200 43208 process1 pid3
90200 43208 process1 pid4
Wednesday May 16 12:00:45 IST 2007
90376 44136 process1 pid1
90200 43208 process1 pid2
90200 43208 process1 pid3
90200 43208 process1 pid4
Wednesday May 16 12:01:46 IST 2007
90376 44136 process1 pid1
90200 43208 process1 pid2
90200 43208 process1 pid3
90200 43208 process1 pid4


desired output
date,pid1(1st),pid1(2nd),pid2(1st),pid2(2nd),pid3(1st),pid3(2nd),pid4(1st),pid4(2nd)
Wednesday May 16 11:59:44 IST 2007,90376,44136,90200,43208,90200,43208,90200,43208
Wednesday May 16 12:00:45 IST 2007,90376,44136,90200,43208,90200,43208,90200,43208
Wednesday May 16 12:01:46 IST 2007,90376,44136,90200,43208,90200,43208,90200,43208


Also the number of pid and date/Time may be variant in number.....

I have tried by using for loop and paste option but no luck ...
Anaybody pls suggest

KRegards,
Aparna
# 2  
Old 05-16-2007
Try that:
Code:
awk '
function print_datas() {
   if (datas) print datas;
   datas = "";
}
NF==6 {   # Date/Time
   print_datas();
   datas = $0;
   next;
}
{
   datas = datas "," $1 "," $2;
}
END {
   print_datas();
}
   ' inputfile

Jean-Pierre.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to paste multiple files in parallel?

Hi all, I am trying to paste thousands of files together into a matrix. Each file has only 1 column and all the files have the same number of rows (~27k rows). I tried paste * > output as well as some other for loops but the output only contains the columns from the 1st and last files. The... (8 Replies)
Discussion started by: notimenocall
8 Replies

2. Shell Programming and Scripting

awk script modification - treat certain files differently

awk 'BEGIN{OFS=","} FNR == 1 {if (NR > 1) {print fn,fnr,nl} fn=FILENAME; fnr = 1; nl = 0} {fnr = FNR} /UNUSUAL/ && /\.gz/ ~ /FILENAME/ {nl++} <'{system ("gunzip -cd FILENAME")}' END ... (2 Replies)
Discussion started by: SkySmart
2 Replies

3. Shell Programming and Scripting

paste mutiple files in a loop

file1.txt file2.txt file3.txt desired output is each file is in the same directory, hasthe same number of columns but different rows. i want to be able to paste them into one file. thanks! (5 Replies)
Discussion started by: johnkim0806
5 Replies

4. Shell Programming and Scripting

Help required the cut the whole contents from one file and paste it into new file

Hi, First of all sincere apologies if I have posted in a wrong section ! Please correct me if I am wrong ! I am very new to UNIX scripting. Currently my problem is that I have a code file at the location /home/usr/workarea/GeneratedLogs.log :- Code :- (Feb 7, 571 7:07:29 AM),... (4 Replies)
Discussion started by: acidburn_007
4 Replies

5. UNIX for Dummies Questions & Answers

Copy/Paste data in files

Hi, I want to put the following values into Variables R2=0.999863 , V2=118.870318 , D2=-178.887511 and so on. There are six values for each variable R2-R8, V2-V8 and D2-D8, total of 18 values for all the variables. Can any one help me to copy and paste all the values in their respective... (2 Replies)
Discussion started by: sullah
2 Replies

6. Shell Programming and Scripting

Paste the files

Dear All, I have thousands of files (consists of one column each) and i need to paste all the columns in a single file as follows: I have files - file1, file2, file3, .......file2000. I need to paste all the files in a single file of separate columns as shown below: file1 file2 file3 ... (3 Replies)
Discussion started by: Fredrick
3 Replies

7. UNIX for Dummies Questions & Answers

paste more than 12 files together

Hi, 1. How can I get around the issue with pasting more than 12 files together? 2. paste file1 file2 > file3........how can I do this with awk?? Thanks! (14 Replies)
Discussion started by: bobo
14 Replies

8. Shell Programming and Scripting

paste several files

Hi everybody: I tried to paste several files which have the same pattern name file like this: down_s1.dat, down_s2.dat, down_s3.dat, down_s4.dat ... down_s10.dat So I have tried to do it as: paste down_s.dat > final.dat But it does not work correctly. Any suggestion. Thanks in... (1 Reply)
Discussion started by: tonet
1 Replies

9. UNIX for Dummies Questions & Answers

paste 2 files ( it is possible???)

Hello all, I have two files: file1: data1 data2 data3 data4 data5 data6 data7 data8 data9 file2: reference I need to paste both files with the following output: data1 data2 data3 reference data4 data5 data6 reference data7 data8 data9 reference I tried using the paste... (3 Replies)
Discussion started by: mig28mx
3 Replies

10. Shell Programming and Scripting

Need a Help with paste 2 files since the output is not what i want

Need a Help with paste 2 files since the output is not what i want ie: i have 2 files pwd /home/pavargaz/alejo/scan01/nokia/2006/abril/bavaria/chu0 $ cat filechu chu0 dia Cantidad 01 257 02 262 03 260 04 58 $pwd ... (3 Replies)
Discussion started by: alexcol
3 Replies
Login or Register to Ask a Question