Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.user > #262597

Re: can you parse and "tail" at once? (and if you can't why not?)

From Greg Wooledge <greg@wooledge.org>
Newsgroups linux.debian.user
Subject Re: can you parse and "tail" at once? (and if you can't why not?)
Date 2023-10-23 14:20 +0200
Message-ID <Hs24x-h75-1@gated-at.bofh.it> (permalink)
References <HrJEB-5ma-7@gated-at.bofh.it> <HrY0V-em0-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Mon, Oct 23, 2023 at 01:21:43PM +0530, Pankaj Jangid wrote:
> 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.

Whoops!  I completely missed the requirement of removing ".description"
in my original answer.

Here's a corrected version:


#!/bin/bash

inputfile=${1-/whatever}
prefix='[info] 123XYZ: /media/user/1234qwer/Algebraic_Geometry04/20231022040239/'

while IFS= read -r line; do
    line=${line#"$prefix"}
    printf '%s\n' "${line%.description}"
done < <(grep -F -- "$prefix" "$inputfile")


Pankaj's answer is not wrong, but it dropped the "grep" which filters
the lines containing the desired prefix.  I'd also add an $ anchor to
the sed regex, and escape the . with backslash so that it becomes
literal.  This answer also requires counting the fields by hand each
time the prefix changes, which may or may not be a concern.

Back to linux.debian.user | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

can you parse and "tail" at once? (and if you can't why not?) Albretch Mueller <lbrtchx@gmail.com> - 2023-10-22 18:40 +0200
  Re: can you parse and "tail" at once? (and if you can't why not?) Charles Curley <charlescurley@charlescurley.com> - 2023-10-22 19:10 +0200
    Re: can you parse and "tail" at once? (and if you can't why not?) Greg Wooledge <greg@wooledge.org> - 2023-10-22 19:50 +0200
      Re: can you parse and "tail" at once? (and if you can't why not?) Albretch Mueller <lbrtchx@gmail.com> - 2023-10-22 23:00 +0200
        Re: can you parse and "tail" at once? (and if you can't why not?) Andy Smith <andy@strugglers.net> - 2023-10-22 23:20 +0200
          Re: can you parse and "tail" at once? (and if you can't why not?) gene heskett <gheskett@shentel.net> - 2023-10-23 00:30 +0200
            Re: can you parse and "tail" at once? (and if you can't why not?) Albretch Mueller <lbrtchx@gmail.com> - 2023-10-23 03:40 +0200
              Re: can you parse and "tail" at once? (and if you can't why not?) Greg Wooledge <greg@wooledge.org> - 2023-10-23 04:20 +0200
                Re: can you parse and "tail" at once? (and if you can't why not?) <tomas@tuxteam.de> - 2023-10-23 06:50 +0200
                Shell-script variable name case [WAS: Re: can you parse and "tail" at  once? (and if you can't why not?)] David <bouncingcats@gmail.com> - 2023-10-23 16:00 +0200
              Re: can you parse and "tail" at once? (and if you can't why not?) Andy Smith <andy@strugglers.net> - 2023-10-23 22:10 +0200
        Re: can you parse and "tail" at once? (and if you can't why not?) Patrick Wiseman <pwiseman@gmail.com> - 2023-10-23 04:50 +0200
  Re: can you parse and "tail" at once? (and if you can't why not?) Roberto C. Sánchez <roberto@debian.org> - 2023-10-22 19:50 +0200
  Re: can you parse and "tail" at once? (and if you can't why not?) Andy Smith <andy@strugglers.net> - 2023-10-22 20:00 +0200
  Re: can you parse and "tail" at once? (and if you can't why not?) Pankaj Jangid <pankaj@codeisgreat.org> - 2023-10-23 10:00 +0200
    Re: can you parse and "tail" at once? (and if you can't why not?) Greg Wooledge <greg@wooledge.org> - 2023-10-23 14:20 +0200
      Re: can you parse and "tail" at once? (and if you can't why not?) Albretch Mueller <lbrtchx@gmail.com> - 2023-10-24 00:20 +0200

csiph-web