|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
From: qazwart
Date: Thurs, Apr 7 2005 9:20 am Email: "qazwart" <qazw...@gmail.com> Groups: comp.unix.shell Remember that sed has more commands in it than just "s" for substitution: sed '/^$/d' Any line that matches the pattern "/^$/" (blank lines) will be deleted from the input. If you want to delete lines that may contain spaces and tabs, but nothing else, you need to use this: sed '/^[ \t]*$/d The "\t" doesn't work with all versions of sed, so you might need to use a real tab character instead. ============================ sed '/^$/d' works, i.e. removes empty lines, but sed '/^[ \t]*$/d' does not - the lines that have tabs and spaces are still there. I tried sed '/^[]*$/d' (a real tab between the square brackets) and sed '/^*$/d' (a real tab between ^ and *) and neither works. (The real tab does not show up in the command line.) |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
> sed '/^[ \t]*$/d' does not work
Sorry guys, I just found out that 1. I probably missed the space inside the square brackets, and 2. I did not know I need to type a Ctrl-v before typing a real tab in order for the shell to recognize the tab character Now it works. Further, sed 's/[ ]*$//' where there is a space and a tab character between the [ and the ] removes trailing spaces from each line. How can I combine these two sed commands so that both empty lines and trailing spaces (and tabs) are removed? Thanks. |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
hzmonte@hotmail.com wrote:
> From: qazwart > Date: Thurs, Apr 7 2005 9:20 am > Email: "qazwart" <qazw...@gmail.com> > Groups: comp.unix.shell > > Remember that sed has more commands in it than just "s" for > substitution: > > sed '/^$/d' > > Any line that matches the pattern "/^$/" (blank lines) will be deleted > from the input. If you want to delete lines that may contain spaces and > tabs, but nothing else, you need to use this: > > sed '/^[ \t]*$/d > > The "\t" doesn't work with all versions of sed, so you might need to > use a real tab character instead. > > ============================ > sed '/^$/d' works, i.e. removes empty lines, but sed '/^[ \t]*$/d' does > not - the lines that have tabs and spaces are still there. I tried > sed '/^[]*$/d' (a real tab between the square brackets) > and > sed '/^*$/d' (a real tab between ^ and *) > and neither works. (The real tab does not show up in the command > line.) you may try "POSIX character class" to see if it s. sed '/^[[:space:]]*$/d' which removes lines containing only whitespaces(TAB, NEWLINE, SPACE,.....) Xicheng |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
hzmo...@hotmail.com wrote: > > sed '/^[ \t]*$/d' does not work > Sorry guys, I just found out that > 1. I probably missed the space inside the square brackets, and > 2. I did not know I need to type a Ctrl-v before typing a real tab in > order for the shell to recognize the tab character > Now it works. > Further, sed 's/[ ]*$//' > where there is a space and a tab character between the [ and the ] > removes trailing spaces from each line. > How can I combine these two sed commands so that both empty lines and > trailing spaces (and tabs) are removed? Thanks. Just connect them with a simicolon: sed '/^[ ]*$/d; s/[ ]*$//;' Xicheng :-) |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
Xicheng Jia wrote:
> hzmo...@hotmail.com wrote: >>>sed '/^[ \t]*$/d' does not work >>Sorry guys, I just found out that >>1. I probably missed the space inside the square brackets, and >>2. I did not know I need to type a Ctrl-v before typing a real tab in >>order for the shell to recognize the tab character >>Now it works. >>Further, sed 's/[ ]*$//' >>where there is a space and a tab character between the [ and the ] >>removes trailing spaces from each line. >>How can I combine these two sed commands so that both empty lines and >>trailing spaces (and tabs) are removed? Thanks. > > Just connect them with a simicolon: ^^^^^^^^^ An ape's digestive tract? That must be messy. John -- use Perl; program fulfillment |
|
![]() |
| Outils de la discussion | |
|
|