perl, unix: fastest way to merge thousands of small files into one file
The cat
command works nicely:
cat *someglob* > output.txt
It's name (short for concatenate) even gives away its purpose.
If your argument list is too long (i.e. too many files are matched by the glob) you can always use the find
command and pipe the arguments to xargs
.
find . -name \*someglob\* -print0 | xargs -0 cat > output.txt
How can I merge some columns of two files using perl?
Another way to get the requested output is to use one while loop instead of two:
mod.pl
#!/usr/bin/perl
use strict;
use warnings;
open my $input1, '<', "input1.txt" or die qq{Failed to open "input1.txt" for writing: $!};
open my $input2, '<', "input2.txt" or die qq{Failed to open "input2.txt" for writing: $!};
open my $outfile, '>', "outfile.txt" or die qq{Failed to open "outfile.txt" for writing: $!};
while(my $l1 = <$input1>){
my $l2 = <$input2>;
chomp $l1;
chomp $l2;
my @columns1 = split(/ /, $l1);
my @columns2 = split(/ /, $l2);
print $outfile join("\t", $columns1[1-1], $columns2[3-1]),"\n";
}
close($input1);
close($input2);
close($outfile);
#$ perl mod.pl
#$ cat outfile.txt
1 8
2 7
3 4
4 6
Running thousands of commands
Almost identical to Miller's answer except that this will actually run the command and print the corresponding output:
for my $i ('AAA'..'ZZZ') {
my $output = `command.exe -X="$i"`;
print "$i: $output\n";
}
Concatenating multiple text files into a single file in Bash
This appends the output to all.txt
cat *.txt >> all.txt
This overwrites all.txt
cat *.txt > all.txt
What's the fastest way to merge multiple csv files by column?
[...] transposing each csv file and re-saving to disk, and then using the command line to concatenate them [...]
Sounds like Transpose-Cat-Transpose. Use paste for joining files horizontally.
paste -d ',' a.csv b.csv c.csv ... > result.csv
Related Topics
Difference Between The Commands "Gcloud Compute Ssh" and "Ssh"
Prevalence of 64Bit Vs 32Bit Platforms
Sublimetext3 Build on The Server Over Ssh
Linux Read Whitespaces and Special Characters
How to Change Some "Special" Gui Colors in Eclipse
Get Apache Total CPU Usage in (Linux)
How to Enter Private Key Password with Ansible
Fork, Execlp and Kill. Zombie Process
Kill Background Process on Sigint
How to Script Multiple Ssh and Scp Commands to Various Systems
How to Use Named Mutex at Linux
Please Help Me "Binary Operator Expected in Cygwin"
How to Use Xdotool to Enter a Web Console Command
Linux Select() and Fifo Ordering of Multiple Sockets
Libnetfilter_Queue Programming, How to Know Which Program Send The Packet
Bypass Dev/Urandom|Random for Testing