Sponsored Content
Full Discussion: Awk - join multiple files
Top Forums Shell Programming and Scripting Awk - join multiple files Post 302664997 by elixir_sinari on Monday 2nd of July 2012 12:22:44 AM
Old 07-02-2012
Code:
$ cat join.awk
{
 totalcnt[$1]++
 if(FILENAME != prevfilename)
  filesc++
 filecnt[filesc,$1]++
 fname[filesc]=prevfilename=FILENAME
}

END {
 for(i in totalcnt)
 {
  printf("%s\t%s",i,totalcnt[i])
  for(j=1;j<=filesc;j++)
  {
   printf("\t%s[%d]",fname[j],filecnt[j,i])
  }
  printf("%s","\n");
 }
}


Last edited by elixir_sinari; 07-02-2012 at 01:32 AM..
This User Gave Thanks to elixir_sinari For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk Join multiple lines

Hi, I have data with broken lines: Sample data: "12"|"25"|"a"|"b"|"c"|"d"|"e"|"f"|"2453748"|"08:10:50" "16"|"25"|"a"|"b"|"c"|"d"|"e"|"f"|" 2453748"|"08:15:50" "16"|"25"|"a"|"b"|" c"|"d"|"e"|"f"|"2453748"|"08:19:50" "16"|"25"|"a"|"b"|"c"|"d"|"e"|"f"|"2453748"|"08:19:50" In the... (5 Replies)
Discussion started by: hitmansilentass
5 Replies

2. UNIX for Dummies Questions & Answers

Join 2 files with multiple columns: awk/grep/join?

Hello, My apologies if this has been posted elsewhere, I have had a look at several threads but I am still confused how to use these functions. I have two files, each with 5 columns: File A: (tab-delimited) PDB CHAIN Start End Fragment 1avq A 171 176 awyfan 1avq A 172 177 wyfany 1c7k A 2 7... (3 Replies)
Discussion started by: InfoSeeker
3 Replies

3. Shell Programming and Scripting

How to join multiple files?

I am trying to join a few hundred files using join. Is there a way to use while read or something else to automate this. My problem is the following. Day 1 City Temp ABC 20 DEF 30 HIJ 15 Day 2 City Temp ABC 22 DEF 29 KLM 5 Day 3 (3 Replies)
Discussion started by: theFinn
3 Replies

4. Shell Programming and Scripting

Join multiple files by column with awk

Hi all, I searched through the forum but i can't manage to find a solution. I need to join a set of files placed in a directory (~1600) by column, and obtain an output with first and second column common to each file, but following columns are taken from the file in the list (precisely the fourth... (10 Replies)
Discussion started by: macsx82
10 Replies

5. UNIX for Dummies Questions & Answers

How to use the the join command to join multiple files by a common column

Hi, I have 20 tab delimited text files that have a common column (column 1). The files are named GSM1.txt through GSM20.txt. Each file has 3 columns (2 other columns in addition to the first common column). I want to write a script to join the files by the first common column so that in the... (5 Replies)
Discussion started by: evelibertine
5 Replies

6. Shell Programming and Scripting

Sort and join multiple columns using awk

Is it possible to join all the values after sorting them based on 1st column key and replace empty rows with 0 like below ? input a1 0 a1 1 a1 1 a3 1 b2 1 a2 1 a4 1 a2 1 a4 1 c4 1 a3 1 d1 1 a3 1 b1 1 d1 1 a4 1 c4 1 b2 1 b1 1 b2 1 c4 1 d1 1 output... (8 Replies)
Discussion started by: quincyjones
8 Replies

7. Shell Programming and Scripting

Join multiple files

Hi there, I am trying to join 24 files (i showed example of 3 files below). They all have 2 columns. The first columns is common to all. The files are tab delimited eg file 1 rs0001 100e-34 rs0003 2.8e-01 rs008 1.9e-90 file 2 rs0001 1.98e-22 rs0004 3.77e-10... (4 Replies)
Discussion started by: fat
4 Replies

8. Shell Programming and Scripting

Join multiple files with filename

Please help, I want to join multiple files based on column 1, and put the missing values as 0. Also the colname in the output should say which file the values came from. FILE1 1 11 2 12 3 13 FILE2 2 22 3 23 4 24 FILE3 1 31 3 33 4 34 FILE1 FILE2 FILE3 1 11 0 31 (1 Reply)
Discussion started by: newbie83
1 Replies

9. Shell Programming and Scripting

Join files on multiple fields

Hello all, I want to join 2 tabbed files on the first 2 fields, and filling the missing values with 0. The 3rd column in each file is constant for the entire file. file1 12658699 ST5 XX2720 0 1 0 1 53039541 ST5 XX2720 1 0 1.5 1 file2 ... (6 Replies)
Discussion started by: sheetalk
6 Replies

10. Shell Programming and Scripting

Join, merge, fill NULL the void columns of multiples files like sql "LEFT JOIN" by using awk

Hello, This post is already here but want to do this with another way Merge multiples files with multiples duplicates keys by filling "NULL" the void columns for anothers joinning files file1.csv: 1|abc 1|def 2|ghi 2|jkl 3|mno 3|pqr file2.csv: 1|123|jojo 1|NULL|bibi... (2 Replies)
Discussion started by: yjacknewton
2 Replies
SmbClient(3pm)						User Contributed Perl Documentation					    SmbClient(3pm)

NAME
Filesys::SmbClient - Interface for access Samba filesystem with libsmclient.so SYNOPSIS
use POSIX; use Filesys::SmbClient; my $smb = new Filesys::SmbClient(username => "alian", password => "speed", workgroup => "alian", debug => 10); # Read a file my $fd = $smb->open("smb://jupiter/doc/general.css", '0666'); while (defined(my $l= $smb->read($fd,50))) {print $l; } $smb->close(fd); # ... See section EXAMPLE for others scripts. DESCRIPTION
Provide interface to access routine defined in libsmbclient.so provided with Samba. Since 3.0 release of this package, you need a least samba-3.0.2. For prior release of Samba, use Filesys::SmbClient version 1.x. For old and 2.x release, this library is available on Samba source, but is not build by default. Do "make bin/libsmbclient.so" in sources directory of Samba to build this libraries. Then copy source/include/libsmbclient.h to /usr/local/samba/include and source/bin/libsmbclient.so to /usr/local/samba/lib before install this module. If you want to use filehandle with this module, you need Perl 5.6 or later. When a path is used, his scheme is : smb://server/share/rep/doc VERSION
$Revision: 3.1 $ FONCTIONS
new %hash Init connection Hash can have this keys: o username o password o workgroup o debug o flags : See set_flag Return instance of Filesys::SmbClient on succes, die with error else. Example: my $smb = new Filesys::SmbClient(username => "alian", password => "speed", workgroup => "alian", debug => 10); set_flag Set flag for smb connection. See _SMBCCTX->flags in libsmclient.h Flag can be: SMB_CTX_FLAG_USE_KERBEROS SMB_CTX_FLAG_FALLBACK_AFTER_KERBEROS SMBCCTX_FLAG_NO_AUTO_ANONYMOUS_LOGON Tie Filesys::SmbClient filehandle This didn't work before 5.005_64. Why, I don't know. When you have tied a filehandle with Filesys::SmbClient, you can call classic methods for filehandle: print, printf, seek, syswrite, getc, open, close, read. See perldoc for usage. Example: local *FD; tie(*FD, 'Filesys::SmbClient'); open(FD,"smb://jupiter/doc/test") or print "Can't open file:", $!, " "; while(<FD>) { print $_; } close(FD); or local *FD; tie(*FD, 'Filesys::SmbClient'); open(FD,">smb://jupiter/doc/test") or print "Can't create file:", $!, " "; print FD "Samba test"," "; printf FD "%s", "And that work ! "; close(FD); Directory mkdir FILENAME, MODE Create directory $fname with permissions set to $mode. Return 1 on success, else 0 is return and errno and $! is set. Example: $smb->mkdir("smb://jupiter/doc/toto",'0666') or print "Error mkdir: ", $!, " "; rmdir FILENAME Erase directory $fname. Return 1 on success, else 0 is return and errno and $! is set. ($fname must be empty, else see rmdir_recurse). Example: $smb->rmdir("smb://jupiter/doc/toto") or print "Error rmdir: ", $!, " "; rmdir_recurse FILENAME Erase directory $fname. Return 1 on success, else 0 is return and errno and $! is set. Il $fname is not empty, all files and dir will be deleted. Example: $smb->rmdir_recurse("smb://jupiter/doc/toto") or print "Error rmdir_recurse: ", $!, " "; opendir FILENAME Open directory $fname. Return file descriptor on succes, else 0 is return and $! is set. readdir FILEHANDLE Read a directory. In a list context, return the full content of the directory $fd, else return next element. Each elem is a name of a directory or files. Return undef at end of directory. Example: my $fd = $smb->opendir("smb://jupiter/doc"); foreach my $n ($smb->readdir($fd)) {print $n," ";} close($fd); readdir_struct FILEHANDLE Read a directory. In a list context, return the full content of the directory FILEHANDLE, else return next element. Each element is a ref to an array with type, name and comment. Type can be : SMBC_WORKGROUP SMBC_SERVER SMBC_FILE_SHARE SMBC_PRINTER_SHARE SMBC_COMMS_SHARE SMBC_IPC_SHARE SMBC_DIR SMBC_FILE SMBC_LINK Return undef at end of directory. Example: my $fd = $smb->opendir("smb://jupiter/doc"); while (my $f = $smb->readdir_struct($fd)) { if ($f->[0] == SMBC_DIR) {print "Directory ",$f->[1]," ";} elsif ($f->[0] == SMBC_FILE) {print "File ",$f->[1]," ";} # ... } close($fd); closedir FILEHANDLE Close directory $fd. Files stat FILENAME Stat a file FILENAME. Return a list with info on success, else an empty list is return and $! is set. List is made with: o device o inode o protection o number of hard links o user ID of owner o group ID of owner o device type (if inode device) o total size, in bytes o blocksize for filesystem I/O o number of blocks allocated o time of last access o time of last modification o time of last change Example: my @tab = $smb->stat("smb://jupiter/doc/tata"); if ($#tab == 0) { print "Erreur in stat:", $!, " "; } else { for (10..12) {$tab[$_] = localtime($tab[$_]);} print join(" ",@tab); } fstat FILEHANDLE Like stat, but on a file handle rename OLDNAME,NEWNAME Changes the name of a file; an existing file NEWNAME will be clobbered. Returns true for success, false otherwise, with $! set. Example: $smb->rename("smb://jupiter/doc/toto","smb://jupiter/doc/tata") or print "Can't rename file:", $!, " "; unlink FILENAME Unlink FILENAME. Return 1 on success, else 0 is return and errno and $! is set. Example: $smb->unlink("smb://jupiter/doc/test") or print "Can't unlink file:", $!, " "; open FILENAME open FILENAME, MODE Open file $fname with perm $mode. Return file descriptor on success, else 0 is return and $! is set. Example: my $fd = $smb->open("smb://jupiter/doc/test", 0666) or print "Can't read file:", $!, " "; my $fd = $smb->open(">smb://jupiter/doc/test", 0666) or print "Can't create file:", $!, " "; my $fd = $smb->open(">>smb://jupiter/doc/test", 0666) or print "Can't append to file:", $!, " "; read FILEHANDLE read FILEHANDLE, LENGTH Read $count bytes of data on file descriptor $fd. It lenght is not set, 4096 bytes will be read. Return buffer read on success, undef at end of file, -1 is return on error and $! is set. FILEHANDLE must be open with open of this module. write FILEHANDLE, $buf write FILEHANDLE, @buf Write $buf or @buf on file descriptor $fd. Return number of bytes wrote, else -1 is return and errno and $! is set. Example: my $fd = $smb->open(">smb://jupiter/doc/test", 0666) or print "Can't create file:", $!, " "; $smb->write($fd, "A test of write call") or print $!," "; $smb->close($fd); FILEHANDLE must be open with open of this module. seek FILEHANDLE, POS Sets FILEHANDLE's position, just like the "fseek" call of "stdio". FILEHANDLE may be an expression whose value gives the name of the filehandle. The values for WHENCE is always SEEK_SET beacause others didn't work on libsmbclient.so FILEHANDLE must be open with open of this module. close FILEHANDLE Close file FILEHANDLE. Return 0 on success, else -1 is return and errno and $! is set. Print method unlink_print_job PRINTER_URL, IDJOB Remove job number IDJOB on printer PRINTER_URL print_file DOCUMENT_URL, PRINTER_URL Print file DOCUMENT_URL on PRINTER_URL TODO
o chown o chmod o open_print_job o telldir o lseekdir EXAMPLE
This module come with some scripts: t/*.t Just for check that this module is ok :-) smb2www-2.cgi A CGI interface with these features: o browse workgroup ,share, dir o read file o upload file o create directory o unlink file, directory COPYRIGHT
The Filesys-SmbClient module is Copyright (c) 1999-2003 Alain BARBET, France, alian at cpan.org. All rights reserved. You may distribute under the terms of either the GNU General Public License or the Artistic License, as specified in the Perl README file. perl v5.14.2 2006-09-13 SmbClient(3pm)
All times are GMT -4. The time now is 07:55 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy