Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.debian.user > #197301
| From | David Christensen <dpchrist@holgerdanske.com> |
|---|---|
| Newsgroups | linux.debian.user |
| Subject | Re: Editing a piped in stream? |
| Date | 2018-07-07 04:10 +0200 |
| Message-ID | <w8KPD-2CT-1@gated-at.bofh.it> (permalink) |
| References | <w8BCG-5u7-11@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On 07/06/18 09:17, Richard Owlett wrote:
> Subject line is poorly phrased.
> While working on a problem {solved by a different approach} I had:
> ls -l /dev/disk/by-label/ | cut -f 10,12 -d ' ' data.txt
> I would then manually edit data.txt by replacing the space character
> between the two fields with a tab.
I assume you meant:
ls -l /dev/disk/by-label/ | cut -f 10,12 -d ' ' > data.txt
(It is best to cut and paste from a console session, rather than typing
untested commands and/or output into a post.)
> I suspect I should be able to do:
> ls -l /dev/disk/by-label/ | cut -f 10,12 -d ' ' | *something* >
> prettydata.txt
>
> I searched for examples/tutorials found that it should be conceptually
> possible. However the examples I found were processing streams I didn't
> understand.
>
> What should I be looking for?
Beware that ls(1) with the -l option can produce output with a variable
number of spaces between fields:
2018-07-06 18:51:53 dpchrist@po ~
$ ls -l /bin/e*
-rwxr-xr-x 1 root root 31464 Feb 22 2017 /bin/echo
-rwxr-xr-x 1 root root 28 Jan 23 2017 /bin/egrep
When you feed that to cut(1) and change the delimiter to a space, the
result is broken (and impossible to fix?) because cut(1) expects exactly
one delimiter between each field:
2018-07-06 18:52:27 dpchrist@po ~
$ ls -l /bin/e* | cut -f 6,7,9 -d ' '
Feb 22 2017
Jan
What you want is a tool that can handle fields delimited by one or more
whitespace characters. Regular expressions come to mind, but RTFM
cut(1) doesn't look promising:
2018-07-06 18:53:45 dpchrist@po ~
$ ls -l /bin/e* | cut -f 6,7,9 -d '\s+'
cut: the delimiter must be a single character
Try 'cut --help' for more information.
Perhaps awk(1) or sed(1) (?).
Perl with the -a (autosplit) and -e (evaluate) options is ideal in this
situation, replacing both cut(1) and "something":
2018-07-06 18:55:29 dpchrist@po ~
$ ls -l /bin/e* | perl -ae 'print join("\t", @F[5,6,7]), "\n"'
Feb 22 2017
Jan 23 2017
Perhaps other people will post solutions in their favorite scripting/
programming language. These give you more power and control than
traditional shell pipelines and command-line tools. You should consider
learning one.
David
Back to linux.debian.user | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Editing a piped in stream? Richard Owlett <rowlett@cloud85.net> - 2018-07-06 18:20 +0200
Re: Editing a piped in stream? Michael Wagner <wagner_m_bremen@web.de> - 2018-07-06 18:50 +0200
Re: Editing a piped in stream? Richard Owlett <rowlett@cloud85.net> - 2018-07-06 20:30 +0200
Re: Editing a piped in stream? john doe <johndoe65534@mail.com> - 2018-07-06 19:10 +0200
Re: Editing a piped in stream? David Christensen <dpchrist@holgerdanske.com> - 2018-07-07 04:10 +0200
Re: Editing a piped in stream? John Crawley <john@bunsenlabs.org> - 2018-07-07 11:00 +0200
Re: Editing a piped in stream? David Christensen <dpchrist@holgerdanske.com> - 2018-07-07 21:40 +0200
Re: Editing a piped in stream? David Wright <deblis@lionunicorn.co.uk> - 2018-07-08 03:40 +0200
Eureka;/ Re: Editing a piped in stream? Richard Owlett <rowlett@cloud85.net> - 2018-07-08 13:00 +0200
Re: Editing a piped in stream? John Crawley <john@bunsenlabs.org> - 2018-07-08 03:40 +0200
Re: Editing a piped in stream? john doe <johndoe65534@mail.com> - 2018-07-08 07:40 +0200
Re: Editing a piped in stream? Andy Smith <andy@strugglers.net> - 2018-07-08 13:20 +0200
Re: Editing a piped in stream? Richard Owlett <rowlett@cloud85.net> - 2018-07-08 15:20 +0200
Re: Editing a piped in stream? Richard Owlett <rowlett@cloud85.net> - 2018-07-08 16:00 +0200
Re: Editing a piped in stream? John Darrah <xyllyx@gmail.com> - 2018-07-08 18:50 +0200
Re: Editing a piped in stream? mick crane <mick.crane@gmail.com> - 2018-07-10 14:20 +0200
Re: Editing a piped in stream? Greg Wooledge <wooledg@eeg.ccf.org> - 2018-07-10 14:40 +0200
Re: Editing a piped in stream? mick crane <mick.crane@gmail.com> - 2018-07-10 15:00 +0200
Re: Editing a piped in stream? john doe <johndoe65534@mail.com> - 2018-07-10 15:30 +0200
Re: Editing a piped in stream? mick crane <mick.crane@gmail.com> - 2018-07-10 14:50 +0200
Re: Editing a piped in stream? Greg Wooledge <wooledg@eeg.ccf.org> - 2018-07-09 14:50 +0200
Re: Nvidia drivers Matthew Crews <mattcrews@mattcrews.com> - 2018-07-09 15:20 +0200
Re: Nvidia drivers Matthew Crews <mattcrews@mattcrews.com> - 2018-07-09 20:40 +0200
Re: Nvidia drivers Boyan Penkov <boyan.penkov@gmail.com> - 2018-07-09 20:50 +0200
csiph-web