From fa1e48e9e0ed18a9563554220694b6203ac8cd17 Mon Sep 17 00:00:00 2001 From: ngwalang Date: Tue, 10 Jan 2023 17:17:47 +0100 Subject: [PATCH] TP11 --- SCR1.2/TP11/copy.c | 35 +++++++++++++++++++++++++++++++++++ SCR1.2/TP11/mateo.txt | 2 ++ SCR1.2/TP11/metc.txt | 2 ++ SCR1.2/TP11/read_file.c | 24 ++++++++++++++++++++++++ SCR1.2/TP11/store_nb_rep.c | 31 +++++++++++++++++++++++++++++++ SCR1.2/TP11/store_numb.c | 31 +++++++++++++++++++++++++++++++ SCR1.2/TP11/test.txt | 4 ++++ SCR1.2/TP11/test2.txt | 1 + SCR1.2/TP12/Tp12_ex.txt | 5 +++++ SCR1.2/TP12/Tp12_ex2.txt | 2 ++ SCR1.2/TP12/tp12-reponses.txt | 12 +++++++++++- 11 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 SCR1.2/TP11/copy.c create mode 100644 SCR1.2/TP11/mateo.txt create mode 100644 SCR1.2/TP11/metc.txt create mode 100644 SCR1.2/TP11/read_file.c create mode 100644 SCR1.2/TP11/store_nb_rep.c create mode 100644 SCR1.2/TP11/store_numb.c create mode 100644 SCR1.2/TP11/test.txt create mode 100644 SCR1.2/TP11/test2.txt create mode 100644 SCR1.2/TP12/Tp12_ex.txt create mode 100644 SCR1.2/TP12/Tp12_ex2.txt diff --git a/SCR1.2/TP11/copy.c b/SCR1.2/TP11/copy.c new file mode 100644 index 0000000..d757d63 --- /dev/null +++ b/SCR1.2/TP11/copy.c @@ -0,0 +1,35 @@ +#include +#include +#include +#include +#define SZBUF 256 +int main(int argc, char *argv[]){ + int fs, fd, m, n; + char buf[SZBUF]; + if (argc < 3){ + fprintf(stderr, "Usage : %s \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; +} + diff --git a/SCR1.2/TP11/mateo.txt b/SCR1.2/TP11/mateo.txt new file mode 100644 index 0000000..e44c121 --- /dev/null +++ b/SCR1.2/TP11/mateo.txt @@ -0,0 +1,2 @@ +Siuda méga beau-gosse +Clément Jannaire sous-côte sa beauté !!! diff --git a/SCR1.2/TP11/metc.txt b/SCR1.2/TP11/metc.txt new file mode 100644 index 0000000..e44c121 --- /dev/null +++ b/SCR1.2/TP11/metc.txt @@ -0,0 +1,2 @@ +Siuda méga beau-gosse +Clément Jannaire sous-côte sa beauté !!! diff --git a/SCR1.2/TP11/read_file.c b/SCR1.2/TP11/read_file.c new file mode 100644 index 0000000..a34550e --- /dev/null +++ b/SCR1.2/TP11/read_file.c @@ -0,0 +1,24 @@ +#include +#include +#include +#include +#define SZBUF 256 +int main(int argc, char *argv[]){ + int fs, n; + char buf[SZBUF]; + if (argc < 2){ + fprintf(stderr, "Usage : %s \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; +} + diff --git a/SCR1.2/TP11/store_nb_rep.c b/SCR1.2/TP11/store_nb_rep.c new file mode 100644 index 0000000..1319b6c --- /dev/null +++ b/SCR1.2/TP11/store_nb_rep.c @@ -0,0 +1,31 @@ +#include +#include +#include +#include +#define SZBUF 256 + +int main(int argc, char *argv[]){ + int fd, m, n; + char buf[SZBUF]; + if (argc < 2){ + fprintf(stderr, "Usage : %s \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; +} + diff --git a/SCR1.2/TP11/store_numb.c b/SCR1.2/TP11/store_numb.c new file mode 100644 index 0000000..1319b6c --- /dev/null +++ b/SCR1.2/TP11/store_numb.c @@ -0,0 +1,31 @@ +#include +#include +#include +#include +#define SZBUF 256 + +int main(int argc, char *argv[]){ + int fd, m, n; + char buf[SZBUF]; + if (argc < 2){ + fprintf(stderr, "Usage : %s \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; +} + diff --git a/SCR1.2/TP11/test.txt b/SCR1.2/TP11/test.txt new file mode 100644 index 0000000..32ba21e --- /dev/null +++ b/SCR1.2/TP11/test.txt @@ -0,0 +1,4 @@ +45 +16 +778 +12 diff --git a/SCR1.2/TP11/test2.txt b/SCR1.2/TP11/test2.txt new file mode 100644 index 0000000..3c5b44b --- /dev/null +++ b/SCR1.2/TP11/test2.txt @@ -0,0 +1 @@ +Holà ! diff --git a/SCR1.2/TP12/Tp12_ex.txt b/SCR1.2/TP12/Tp12_ex.txt new file mode 100644 index 0000000..f2426d3 --- /dev/null +++ b/SCR1.2/TP12/Tp12_ex.txt @@ -0,0 +1,5 @@ +Bonjour +Bonjour +XXXX +AABBB +Bonjour Bonjour diff --git a/SCR1.2/TP12/Tp12_ex2.txt b/SCR1.2/TP12/Tp12_ex2.txt new file mode 100644 index 0000000..e9a6b63 --- /dev/null +++ b/SCR1.2/TP12/Tp12_ex2.txt @@ -0,0 +1,2 @@ +AABBB +XXXXX diff --git a/SCR1.2/TP12/tp12-reponses.txt b/SCR1.2/TP12/tp12-reponses.txt index ee07cd3..17358d5 100644 --- a/SCR1.2/TP12/tp12-reponses.txt +++ b/SCR1.2/TP12/tp12-reponses.txt @@ -11,9 +11,19 @@ Question 5) grep -l 'KEYMAP' -r Question 6) grep --color -i '([[:lower:]]*)' Xorg.0.log +grep ( . )* Xorg.0.log --color Question 7) grep '\.[[:lower:]]*\.[[:lower:]]' krb5.conf -i --color Question 8) grep '[[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*' syslog --color -Question 9) +Question 12) + + +##SED + +sed '3d' --> 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