Skip to content

Instantly share code, notes, and snippets.

@amtc131
Last active June 30, 2023 22:55
Show Gist options
  • Save amtc131/54fbd211d8cefbe1dfdc7b543b3e9778 to your computer and use it in GitHub Desktop.
Save amtc131/54fbd211d8cefbe1dfdc7b543b3e9778 to your computer and use it in GitHub Desktop.
Files with AWK
#! /bin/awk
# Here's an awk scrip that atttemps to set difference of two files based on their first column
# gawk -f Diff.awk file1.txt file2.txt
BEGIN{
OFS=FS="\t"
file = ARGV[1]
while (getline < file)
Contained[$1] = $1
delete ARGV[1]
}
!($1 in Contained){
print $0
}
awk -v filename="archivo_grande.txt" -v partsize="1000000" '
BEGIN {part = 1; file = filename "_" part ".txt"; size = 0}
{
size += length + 1;
if (size > partsize) {
close(file);
part++;
file = filename "_" part ".txt";
size = 0
}
print > file
}
END {close(file)}
' archivo_grande.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment