Bash, sed, remove last line for every cycle

genderbee

Issue

How can I remove last line for this sed cycle?

sed -n '/## bash, file, re/,/##/p' bash.kb

In my case, it shows me the last line too, last line with ## string, which I need to remove.

Example.

Source file bash.kb, this is text file.

...

## bash, file, remove last character on every line
sed 's/.$//' $file

## bash, files, watch only today's modified files
some command.
some 2nd command.

## bash, file, remove duplicate rows by column 1
sort -u -t, -k1,1 $file

## bash, file, exclude
command exclude
command exclude 2

## bash, file, remove all whitespaces from file
command
...

When I enter this command.

sed -n '/## bash, file, re/,/##/p' bash.kb

It will search for ## bash, file, re and display output until next ##, so with next ## head line, which I need to remove.

## bash, file, remove last character on every line
sed 's/.$//' $file

## bash, files, watch only today's modified files
## bash, file, remove duplicate rows by column 1
sort -u -t, -k1,1 $file

## bash, file, exclude
## bash, file, remove all whitespaces from file
command

Output should be like this (implement sed '$d' to every cycle? But how?).

## bash, file, remove last character on every line
sed 's/.$//' $file

## bash, file, remove duplicate rows by column 1
sort -u -t, -k1,1 $file

## bash, file, remove all whitespaces from file
command

Thanks.

Melebius

If your input file has an empty line before every ## line and only there, you can specify an empty line as the end of your range:

sed -n '/## bash, file, re/,/^$/p' bash.kb

^$ matches a line that has the beginning (^), the end of the line ($) and nothing in between.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

how to remove last comma from line in bash using "sed or awk"

Remove last character of every nth line in place

SED not removing last double quote from every line

Bash - Remove the last character of the line this before?

Remove the last line from a file in Bash

sed remove last space only on end of line,combined with awk

how to remove both first and last line of csv file using sed

sed-remove all but last occurrence of a character from a line

How to remove comma in the last line of sed address range?

BASH - SED insert new line before last, containing tab and variable

Omit the last line with sed

Show just specific group of regexp and remove rest of the line in bash with sed

Is there a way to remove a string from a line of a csv using sed in bash scripts?

Remove line from file in bash script using sed command

bash - print a line every X seconds (like sed every X lines)

How to remove the last line from a variable in bash or sh?

Remove a string in every line

remove backslash at every line

How to use sed to remove all trailing Q's, but not remove the last Q if the line is all Q's

How to remove last element of the delimited string using Bash/Sed/Awk/Perl inside bash script

Remove a last blank line

Removing last comma every line

Change last character in line with sed

sed repeating the last line in the stream

Replacing the last line in Bash

Append to last line in bash

why does this line remove everything instead of one line. Crontab-Bash-Sed

Can I double every text line of a file using sed in linux bash?

Use sed to replace the last space in each line with a comma, then remove all spaces