Shell script help
1
Name:
Anonymous
2010-11-03 22:18
How can I change my code to be able to compare the size of two files.
if [ -f $1 ] && [ -f $2 ] && [ ! $1 -ef $2 ]; then
size1=$(du $1)
size2=$(du $2)
if [ $1 -gt $2 ]; then
echo "$1 is bigger"
else
echo "$1 is smaller"
fi
fi
2
Name:
Anonymous
2010-11-03 22:42
intENTERPRISE_C (char *f1, char *f2){
FILE *f1ptr;
FILE *f2ptr;
if(!(f1ptr=fopen(f1,'r')) || !(f2ptr=fopen(f2,'r'))){
fprintf(stderr,"Failed to open files\n");
return -1;
}
if(sizeof(f1ptr) > sizeof(f2ptr))
printf("File 1 is bigger");
else
printf("File 2 is bigger");
return 0;
}
3
Name:
Anonymous
2010-11-03 22:47
in shell, not c++ -_-
4
Name:
Anonymous
2010-11-03 22:48
>>3
that's not C++ you fool, that's
ENTERPRISE C
5
Name:
Anonymous
2010-11-03 23:01
if(sizeof(f1ptr) > sizeof(f2ptr))
i don't think that will work right
6
Name:
Anonymous
2010-11-03 23:07
its for script shell
7
Name:
Anonymous
2010-11-03 23:08
>>5
It won't. That doesn't actually read the size of everything in the file, just the size of the pointer.
8
Name:
Anonymous
2010-11-03 23:50
>>7
>>5
intENTERPRISE_C (char *f1, char *f2){
FILE *f1ptr;
FILE *f2ptr;
if(!(f1ptr=fopen(f1,'b')) || !(f2ptr=fopen(f2,'b'))){
fprintf(stderr,"Failed to open files\n");
return -1;
}
fseek(f1ptr,0,SEEK_END);
fseek(f2ptr,0,SEEK_END);
if(ftell(f1ptr) > ftell(f2ptr))
printf("File 1 is bigger");
else
printf("File 2 is bigger");
return 0;
}
9
Name:
Anonymous
2010-11-04 2:49
>>8
-
"rb"
- A binary stream need not meaningfully support
fseek calls with a
whence value of
SEEK_END. The
fseek function returns nonzero only for a request that cannot be satisfied.
- On failure, the
ftell function returns
−1L.
IHBT
10
Name:
Anonymous
2010-11-04 14:15
11
Name:
Anonymous
2010-11-04 14:58
>>1
Use
stat -c%s "$1" instead of
du $1 and it should work.
12
Name:
Anonymous
2010-11-04 15:24
>>10
intENTERPRISE C (char *f1,char *f2){
printf("File 1 is bigger");
return 0;
}
13
Name:
Anonymous
2010-11-04 16:06
>>12
intENTERPRISE_C(char *f1, char *f2){
if(strlen(f1) > strlen(f2) goto file1;
printf("File 2 is bigger\n");
goto end;
file1:
printf("File 1 is bigger\n");
end:
return 0;
}
14
Name:
Anonymous
2010-11-04 16:07
15
Name:
Anonymous
2010-11-04 17:06
int [b][i][u][o]ENTERPRISE_C[/o][/u][/i][/b](const char *f1, const char *f2)
{
if (f1 > f2)
printf("File 1 is bigger");
else
printf("File 2 is bigger");
return EXIT_SUCCESS;
}
16
Name:
Anonymous
2010-11-04 18:42
/* ftell example : getting size of a file */
#include <stdio.h>
int main ()
{
FILE * pFile;
long size;
pFile = fopen ("myfile.txt","rb");
if (pFile==NULL) perror ("Error opening file");
else
{
fseek (pFile, 0, SEEK_END);
size=ftell (pFile);
fclose (pFile);
printf ("Size of myfile.txt: %ld bytes.\n",size);
}
return 0;
}
17
Name:
Anonymous
2010-11-04 19:03
>>16
/* Get the size of a file. */
#include <stdio.h>
int main(int argc, char *argv[])
{
FILE *file;
long size;
if (argc < 2)
fprintf(stderr, "Please provide a filename argument.\n");
else if ((file = fopen(argv[1], "rb")) == NULL)
fprintf(stderr, "Error opening file.\n");
else if (fseek(file, 0, SEEK_END))
fprintf(stderr, "Error seeking to end of file.\n");
else if ((size = ftell(file)) == -1)
fprintf(stderr, "Error obtaining file position.\n");
else
printf("%ld\n", size);
return 0;
}
18
Name:
Anonymous
2010-11-04 19:40
anus anus anus anus;
19
Name:
Anonymous
2010-11-04 20:44
>>17
pig disgusting error handling
20
Name:
Anonymous
2010-11-04 23:16
look at these sepples. They are ugly. Behold the true power of shell.
#!/bin/bash
function fz()
{
echo $(wc -c <"$1")
}
a=$(fz a.sh)
b=$(fz b.sh)
echo $(($a < $b))
echo $(($a == $b))
echo $(($a > $b))
21
Name:
Anonymous
2010-11-04 23:20
22
Name:
Anonymous
2010-11-04 23:24
>>21
implying there's significant difference between fstream.tellg and ftell(FILE* stream)
23
Name:
Anonymous
2010-11-04 23:39
>>22
just because the process would be closely related and almost the same doesn't equate the C code to be C++
24
Name:
Anonymous
2010-11-04 23:39
C++2x:
int main() {
std::cpp2x::r1::r2::e1::boost::library::type::primitive::integer::bignum count1;
std::cpp2x::r1::r2::e1::boost::library::file::utils::FileStreamObjectHolderIteratorConstructorOverridable<std::cpp2x::r1::r2::e1::boost::library::file::type::readonly> file1("file1");
std::cpp2x::r1::r2::e1::boost::library::file::iterators::for::each::byte_in_file<std::cpp2x::r1::r2::e1::boost::library::file::utils::FileStreamObjectHolderIteratorConstructorOverridable<std::cpp2x::r1::r2::e1::boost::library::file::type::readonly>>(file1.begin(), file1.end(), count1.increment_by(1));
std::cpp2x::r1::r2::e1::boost::library::type::primitive::integer::bignum count2;
std::cpp2x::r1::r2::e1::boost::library::file::utils::FileStreamObjectHolderIteratorConstructorOverridable<std::cpp2x::r1::r2::e1::boost::library::file::type::readonly> file2("file2");
std::cpp2x::r1::r2::e1::boost::library::file::iterators::for::each::byte_in_file<std::cpp2x::r1::r2::e1::boost::library::file::utils::FileStreamObjectHolderIteratorConstructorOverridable<std::cpp2x::r1::r2::e1::boost::library::file::type::readonly>>(file2.begin(), file2.end(), count2.increment_by(1));
std::cpp2x::r1::r2::e1::boost::library::utils::statements::comparison::boolean::if(std::cpp2x::r1::r2::e1::boost::library::types::primitive::integer::bignum::operator>(count1, count2).tostdbool, [std::cpp2x::r1::r2::e1::boost::library::output::stdout.putline(std::cpp2x::r1::r2::e1::boost::library::types::primitive::string("File1 is bigger.")].else(std::cpp2x::r1::r2::e1::boost::library::utils::statements::comparison::boolean::if(std::cpp2x::r1::r2::e1::boost::library::types::primitive::integer::bignum::operator<(count1, count2).tostdbool, [std::cpp2x::r1::r2::e1::boost::library::output::stdout.putline(std::cpp2x::r1::r2::e1::boost::library::types::primitive::string("File2 is bigger.")].else(std::cpp2x::r1::r2::e1::boost::library::output::stdout.putline(std::cpp2x::r1::r2::e1::boost::library::types::primitive::string("They are equal.")))));
}
25
Name:
Anonymous
2010-11-04 23:45
>>23
Except it's C++ code. Or at least my compiler things so.
26
Name:
Anonymous
2010-11-05 0:24
C++++++
27
Name:
Anonymous
2010-11-05 1:20
>>25
>things
what a hell is wrong with me?
28
Name:
Anonymous
2010-11-05 5:31
29
Name:
Anonymous
2010-11-05 18:43
30
Name:
Anonymous
2010-11-06 0:29
section .text
global _start
bail:
mov rdi, 1
jmp exit
usage:
mov rdi, 2
exit:
mov rax, 60
syscall
_start:
pop rax
cmp rax, 2
jnz usage
add rsp, 8
mov rax, 2
pop rdi
mov rsi, 0
syscall
cmp rax, -1
je bail
mov rdi, rax
mov rax, 8
mov rsi, 0
mov rdx, 2
syscall
cmp rax, -1
je bail
mov r9, rax
mov rax, 3
syscall
push 0xa
mov rax, 1
mov rdi, 1
mov rsi, rsp
mov rdx, rdi
syscall
add rsp, 8
lewp:
mov rcx, r9
xor rdx, rdx
mov rax, rcx
mov r8, 10
idiv r8
mov r9, rax ; rcx is clobbered by write()
add rdx, '0'
push rdx
mov rax, 1
mov rdi, 1
mov rsi, rsp
mov rdx, 1
syscall
add rsp, 8
test r9, r9
jz fin
jmp lewp
fin:
mov rdi, 0
jmp exit
You'll need to pipe into rev because I can't be bothered reversing the characters it outputs.
that's the power of Unix for you
33
Name:
Anonymous
2011-01-31 20:17
<-- check em dubz
34
Name:
Anonymous
2011-02-03 1:10