0

The following sed returns (...| od -c) without ...|cut -d "\n" -f

0000000   1   9   2  \n   2   5   0  \n
0000010

Pseudocode

# http://unix.stackexchange.com/a/290407/16920
sed -n -f - /usr/share/X11/xkb/symbols/us <<END_SED | cut -d "\n" -f1 
/xkb_symbols "dvorak" {/,/^};/{
        /xkb_symbols "dvorak" {/=
        /^};/=
}
END_SED

but blank output.

System: Ubuntu 16.04 64 bit
Hardware: Macbook Air 2013-mid
Sed: 4.2.2
Cut, od: Coreutils 8.25

  • what's wrong with @Kusalananda 's answer ? – Archemar Jun 19 '16 at 7:43
  • 1
    I updated my answer to that question in such a way that the output is read into an array variable. The two values are then easily accessed through array index 0 and 1. – Kusalananda Jun 19 '16 at 7:47
  • If you want the first line of output use ... | head -n 1 – steeldriver Jun 19 '16 at 9:09
  • @steeldriver Yes, it works, but I want the second line. – Léo Léopold Hertz 준영 Jun 19 '16 at 9:27
2

The cut utility "cuts" one or several columns out of its input. Like many other Unix utilities, cut is a stream-based line-by-line reader that applies its processing to each line of input and then contiues with the next line.

You can not use \n as the delimiter for cut since that is what it expects separate the lines.

A roundabout way of creating two columns for cut to work with would be to use paste. The paste utility also reads it input line-by-line, but it buffers and outputs it into tab-delimited columns according to the specification that you give it.

In this case:

$ mycommand | paste - -
192     250

Then with cut added:

$ mycommand | paste - - | cut -f1
192

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.