2 Changed first to third to match the code. Also broke it up into dot points and clarified each part of the syntax. Hopefully it's more readable now.
source | link

How do I delete a line only if it is at thea specified line number and it matches the pattern?

 

I want to delete the first line only if it is blank.For example:

  • I want to delete (d);
  • the third line (3);
  • if it's blank (^$);
 

The following syntax does not work:

# cat file |sed| sed '3 /^$/d'

Returns the following error:

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

How do I delete a line only if it is at the specified line number and it matches the pattern?

I want to delete the first line only if it is blank.

The following syntax does not work

# cat file |sed '3 /^$/d'
sed: -e expression #1, char 3: unknown command: `/'

How do I delete a line only if it is at a specified line number and it matches the pattern?

 

For example:

  • I want to delete (d);
  • the third line (3);
  • if it's blank (^$);
 

The following syntax:

cat file | sed '3 /^$/d'

Returns the following error:

sed: -e expression #1, char 3: unknown command: `/'
    Post Closed as "duplicate" by Anthon, Thomas Dickey, Stephen Kitt, Anthony Geoghegan, GAD3R of
    Tweeted twitter.com/StackUnix/status/782680728064712704
1
source | link

How do I delete a line only if it is at the specified line number and it matches the pattern?

How do I delete a line only if it is at the specified line number and it matches the pattern?

I want to delete the first line only if it is blank.

The following syntax does not work

# cat file |sed '3 /^$/d'
sed: -e expression #1, char 3: unknown command: `/'