From 2e5101d6a20897326f8b5325088685491b2d85f0 Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Fri, 14 Jul 2023 10:12:26 +0400 Subject: [PATCH] ajout de lgrep --- lgrep | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 lgrep diff --git a/lgrep b/lgrep new file mode 100755 index 0000000..2f8a994 --- /dev/null +++ b/lgrep @@ -0,0 +1,40 @@ +#!/bin/bash +# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8 +source "$(dirname "$0")/lib/ulib/auto" || exit 1 + +function display_help() { + uecho "$scriptname: frontend de grep pour lire des fichiers encodés en latin1 + +USAGE + $scriptname [options] files... + +OPTIONS + options de grep qui sont reprises telles quelles" +} + +grepopts=() +args=( + --help '$exit_with display_help' + -E,--extended-regexp '$grepopts+=(-E)' + -F,--fixed-strings '$grepopts+=(-F)' + -G,--basic-regexp '$grepopts+=(-G)' + -P,--perl-regexp '$grepopts+=(-P)' + -i,--ignore-case '$grepopts+=(-i)' + -v,--invert-match '$grepopts+=(-v)' + -L,--files-without-match '$grepopts+=(-L)' + -l,--files-with-matches '$grepopts+=(-l)' + -q,--quiet,--silent '$grepopts+=(-q)' + -s,--no-messages '$grepopts+=(-s)' + -H,--with-filename '$grepopts+=(-H)' + -h,--no-filename '$grepopts+=(-h)' + -a,--text '$grepopts+=(-a)' + -r,--recursive '$grepopts+=(-r)' + -R,--dereference-recursive '$grepopts+=(-R)' +) +parse_args "$@"; set -- "${args[@]}" + +pattern="$1" +args=("${@:2}") +#XXX ajouter le support de -r, notamment si ${args[@]} contient un répertoire + +iconv -f latin1 -t utf-8 "${args[@]}" | grep "${grepopts[@]}" "$pattern"