1

I wrote this code:

cat /etc/passwd | cut -d : -f1 | sed -n "${FT_LINE1}, ${FT_LINE2} p"

Output:

sed: -e expression #1, char 1: unknown command: `,'

But I have a problem with variables $FT_LINE1, $FT_LINE2.
When I use constants instead of a variables, this code works correctly

cat /etc/passwd | cut -d : -f1 | sed -n "3, 5 p"

I tried to use these constructions:

sed -n -e "${FT_LINE1}, ${FT_LINE2} p"
sed -n "{$FT_LINE1}, {$FT_LINE2} p"
sed -n "${FT_LINE1},${FT_LINE2} p"
sed -n "${FT_LINE1}, ${FT_LINE2}" p
sed -n "$FT_LINE1, $FT_LINE2" p

but the error remained.

3
  • 4
    What's in the variables? Commented Sep 12, 2018 at 8:02
  • 2
    You didn't set any variables. Commented Sep 12, 2018 at 8:06
  • Thank's you all. @melpomene you're right. Problem solved Commented Sep 12, 2018 at 8:28

1 Answer 1

1

As noted in melpomene and PesaThe's comments, sed address ranges can't be blank, both shell variables ${FT_LINE1}, and ${FT_LINE2}, must be set to some appropriate value.

This simplest way to reproduce the error is:

sed ,

Which outputs:

sed: -e expression #1, char 1: unknown command: `,'

Because , is not a sed command, it's just a delimiter that separates range addresses.

It might help to look at some other related errors. Let's add a starting address of 1:

sed 1,

Output:

sed: -e expression #1, char 2: unexpected `,'

Which seems unhelpful, since it should be expecting an address after the ,. Now let's add a second address of 1:

sed 1,1

Output:

sed: -e expression #1, char 3: missing command

A little better, but really it's char 4 that's missing a command, or rather there's a missing command after char 3.

Now let's add a command, and a bit of input and it works:

echo foo | sed 1,1p

Output:

foo
Sign up to request clarification or add additional context in comments.

1 Comment

Awesome! Thanks for your help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.