Re: can you parse and "tail" at once? (and if you can't why not?)
Albretch Mueller <lbrtchx@gmail.com> writes:
> After generating a file with lines of text, I have to:
> 1) parse some of those lines based on a pattern I know (no regex
> necessary, just a FS path)
> 2) once parsed from those lines I need the last n characters only
> I am trying to use a one liner like:
> cat "${IFL}" | grep "${DESC_DIR}" | tail -c+$_DESC_DIR
> but this one liner repeats the output and the tail
>
> Say the lines of text in IFL are:
> [info] 123XYZ: /media/user/1234qwer/Algebraic_Geometry04/20231022040239/Uppsala_Algebra/45_16.3_45MEB5h5H9Y.description
> [info] 123XYZ: /media/user/1234qwer/Algebraic_Geometry04/20231022040239/Uppsala_Algebra/46_17.1_LE_gl5RcDnY.description
> [info] 123XYZ: /media/user/1234qwer/Algebraic_Geometry04/20231022040239/Göttsche/17_9jKzwoBGFs8.description
> [info] 123XYZ: /media/user/1234qwer/Algebraic_Geometry04/20231022040239/Göttsche/18_plOUIOo91lI.description
> [info] 123XYZ: /media/user/1234qwer/Algebraic_Geometry04/20231022040239/Göttsche/19_TJ7yAiq8gEw.description
> [info] 123XYZ: /media/user/1234qwer/Algebraic_Geometry04/20231022040239/Göttsche/20_UMBEgb14uqw.description
>
> I know the prefix:
> [info] 123XYZ: /media/user/1234qwer/Algebraic_Geometry04/20231022040239/
>
> I need as output:
>
> Uppsala_Algebra/45_16.3_45MEB5h5H9Y
> Uppsala_Algebra/46_17.1_LE_gl5RcDnY
> Göttsche/17_9jKzwoBGFs8
> Göttsche/18_plOUIOo91lI
> Göttsche/19_TJ7yAiq8gEw
> Göttsche/20_UMBEgb14uqw
> ~
> lbrtchx
Another way to do it is,
cat "${IFL}"| cut -d "/" -f7-|sed 's/.description//'
because you already know the prefix, you can count the fields. So "-f7-"
i.e. 7 onwards. Then use sed to remove the extension.
Reply to: