This commit is contained in:
Arnaud NGWALA NGWALA 2023-01-10 17:17:47 +01:00
parent e2cc18da4d
commit fa1e48e9e0
11 changed files with 148 additions and 1 deletions

35
SCR1.2/TP11/copy.c Normal file
View File

@ -0,0 +1,35 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#define SZBUF 256
int main(int argc, char *argv[]){
int fs, fd, m, n;
char buf[SZBUF];
if (argc < 3){
fprintf(stderr, "Usage : %s <SRC_FILE> <DST_FILE>\n", argv[0]);
exit(1);
}
fs = open(argv[1], O_RDONLY);
if (fs == -1){
perror("Opening source file fails");
exit(2);
}
fd = open(argv[2], O_WRONLY|O_TRUNC|O_CREAT, 0600);
if (fd == -1){
perror("Opening destination file fails");
exit(3);
}
while (n = read(fs, buf, SZBUF)){
m = write(fd , buf, n);
if (n == -1){
perror("Writing in file fails");
exit(4);
}
}
close(fd);
close(fs);
exit(0);
return EXIT_SUCCESS;
}

2
SCR1.2/TP11/mateo.txt Normal file
View File

@ -0,0 +1,2 @@
Siuda méga beau-gosse
Clément Jannaire sous-côte sa beauté !!!

2
SCR1.2/TP11/metc.txt Normal file
View File

@ -0,0 +1,2 @@
Siuda méga beau-gosse
Clément Jannaire sous-côte sa beauté !!!

24
SCR1.2/TP11/read_file.c Normal file
View File

@ -0,0 +1,24 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#define SZBUF 256
int main(int argc, char *argv[]){
int fs, n;
char buf[SZBUF];
if (argc < 2){
fprintf(stderr, "Usage : %s <SRC_FILE>\n", argv[0]);
exit(1);
}
fs = open(argv[1], O_RDONLY);
if (fs == -1){
perror("File opening fails");
exit(2);
}
while (n = read(fs, buf, SZBUF))
write(1, buf, n);
close(fs);
exit(0);
return EXIT_SUCCESS;
}

View File

@ -0,0 +1,31 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#define SZBUF 256
int main(int argc, char *argv[]){
int fd, m, n;
char buf[SZBUF];
if (argc < 2){
fprintf(stderr, "Usage : %s <DST_FILE>\n", argv[0]);
exit(1);
}
fd = open(argv[1], O_WRONLY|O_TRUNC|O_CREAT ,0644);
if (fd == -1){
perror("Cannot open destination file");
exit(2);
}
write(1, "Nomb --> ", 9);
while (n=read(0, buf, SZBUF)){
m=write(fd, buf, n);
if (n == -1){
perror("Writing in file fails");
exit(3);
}
write(1, "Nomb --> ", 9);
}
close(fd);
return EXIT_SUCCESS;
}

31
SCR1.2/TP11/store_numb.c Normal file
View File

@ -0,0 +1,31 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#define SZBUF 256
int main(int argc, char *argv[]){
int fd, m, n;
char buf[SZBUF];
if (argc < 2){
fprintf(stderr, "Usage : %s <DST_FILE>\n", argv[0]);
exit(1);
}
fd = open(argv[1], O_WRONLY|O_TRUNC|O_CREAT ,0644);
if (fd == -1){
perror("Cannot open destination file");
exit(2);
}
write(1, "Nomb --> ", 9);
while (n=read(0, buf, SZBUF)){
m=write(fd, buf, n);
if (n == -1){
perror("Writing in file fails");
exit(3);
}
write(1, "Nomb --> ", 9);
}
close(fd);
return EXIT_SUCCESS;
}

4
SCR1.2/TP11/test.txt Normal file
View File

@ -0,0 +1,4 @@
45
16
778
12

1
SCR1.2/TP11/test2.txt Normal file
View File

@ -0,0 +1 @@
Holà !

5
SCR1.2/TP12/Tp12_ex.txt Normal file
View File

@ -0,0 +1,5 @@
Bonjour
Bonjour
XXXX
AABBB
Bonjour Bonjour

2
SCR1.2/TP12/Tp12_ex2.txt Normal file
View File

@ -0,0 +1,2 @@
AABBB
XXXXX

View File

@ -11,9 +11,19 @@ Question 5)
grep -l 'KEYMAP' -r grep -l 'KEYMAP' -r
Question 6) Question 6)
grep --color -i '([[:lower:]]*)' Xorg.0.log grep --color -i '([[:lower:]]*)' Xorg.0.log
grep ( . )* Xorg.0.log --color
Question 7) Question 7)
grep '\.[[:lower:]]*\.[[:lower:]]' krb5.conf -i --color grep '\.[[:lower:]]*\.[[:lower:]]' krb5.conf -i --color
Question 8) Question 8)
grep '[[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*' syslog --color grep '[[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*' syslog --color
Question 9) Question 12)
##SED
sed '3d' <nom_fichier> --> Affiche le contenu d'un fichier sans la 3ème ligne
sed 's/Bonjour/Salut/' Tp12_ex.txt --> Cherche toutes les occurences de "Bonjour" pour remplacer la première occurence dans la ligne
sed 's/Bonjour/Salut/g' Tp12_ex.txt --> Cherche toutes les occurences de "Bonjour" dans le fichier pour les remplacer par "Salut"
sed -E 's/[[:upper:]]{2,5}/CONFIDENTIAL/g' Tp12_ex.txt --> Remplace les mots avec entre 2 et 5 majuscules par CONFIDENTIAL
find -name 'Tp12*' -exec sed 's/AABBB/Yeah/g' {} \; --> Cherche dans les fichiers comportant Tp12 dans leur nom et remplace les occurences de AABBB par Yeah pour ensuite les afficher