why the <tab> could be not recognized in grep and sed?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers why the <tab> could be not recognized in grep and sed?
# 1  
Old 06-27-2008
why the <tab> could be not recognized in grep and sed?

I try to remove empty lines from file and use next:
Code:
> cat fl.dat|grep -v '^[<spc><tab>]*$'

or
Code:
cat fl.dat|sed '/^[<spc><tab>]*$/d'

'grep' does not removes lines with tabs, 'sed' - lines with <tab> and with <spc>

Why it could be?
Is there any option/env-var should I check?

Thank you
Alex
# 2  
Old 06-27-2008
try:
Code:
sed '/^$/d' file > newfile
or
sed '/^[ \t]*$/d' file > newfile

The first one works for blank lines made of a newline character only.
# 3  
Old 06-27-2008
Quote:
Originally Posted by jim mcnamara
try:
Code:
sed '/^$/d' file > newfile
or
sed '/^[ \t]*$/d' file > newfile

The first one works for blank lines made of a newline character only.
Thank you for answer.
'\t' doesn't work for some reason, too!

That what I try to figured out: why it could be?

Removing empty lines works fine.
The [ \t] was my original attempt to do that and after that I start to search for different way to patterning the tab and found those macros: <spc>,<tab>, but that does not work for me for some reason.

I perfectly removing all 'blank' line with
Code:
nawk 'NF' file

Any advices why the tab specifiers could doesn't work for me?
# 4  
Old 06-27-2008
The blank lines have other non-printing characters - not tabs.
try
Code:
od -c file | more

to see what other stuff is in there.
# 5  
Old 06-28-2008
Old versions of sed don't recognize "\t" as a tab, type between the brackets a <space> followed by <Ctrl-v> <TAB> to delete the lines with spaces or/and tabs:

Code:
sed '/[     ]/d' file > newfile

Regards
# 6  
Old 06-30-2008
Quote:
Originally Posted by jim mcnamara
The blank lines have other non-printing characters - not tabs.
try
Code:
od -c file | more

to see what other stuff is in there.
Thank you, jim: the 'od' is new for me and usefull command.
I have checked the file, but nothing extra is not found in the file

It seems our system grep and sed just old, as said Franklin52:
Quote:
Originally Posted by Franklin52
Old versions of sed don't recognize "\t" as a tab, type between the brackets a <space> followed by <Ctrl-v> <TAB> to delete the lines with spaces or/and tabs:

Code:
sed '/[     ]/d' file > newfile

Regards
Thank you, Franclin52.
It works in the way you show.

So, I make a note for myself that our system do not know those macros and I need to use Ctrl/v for that.

Appreciate your help, guys!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Grep solutions tab-delimited file

Hello, I am trying to find a solution to problem that's proving to be beyond my newbie skills. The below files comes from a genetics study. File 1 describes a position on the genome and file 2 does the same but is formatted differently and has more information. I am trying to match all lines in... (5 Replies)
Discussion started by: andmal
5 Replies

2. Shell Programming and Scripting

SED - Unable to replace with <tab>

Hello All, I have this file with the below contents 1|2|3|4| this|that|which|what| when I use, sed 's/|/\t/g' infile I get, 1t2t3t4t thistthattwhichtwhatt Why is this?? :confused: :wall: (13 Replies)
Discussion started by: PikK45
13 Replies

3. Shell Programming and Scripting

sed newline to tab ,problem

Input: gstreamer-plugins-good gstreamer-plugins-bad gstreamer-plugins-ugly sed 's/\n/\t/g' infile It's not working. Output should be: gstreamer-plugins-good gstreamer-plugins-bad gstreamer-plugins-ugly (5 Replies)
Discussion started by: cola
5 Replies

4. Shell Programming and Scripting

how to replace new line ( \n ) with space or Tab in Sed

Hi, how to replace new line with tab in sed ... i used sed -e 's/\n/\t/g' <filename > but its not working (1 Reply)
Discussion started by: mail2sant
1 Replies

5. UNIX for Dummies Questions & Answers

Tab spaces with sed

Anyone know how to represent tabs when doing subsitutions in sed? I have tried using \t but it doesn't seem to work. (11 Replies)
Discussion started by: handak9
11 Replies

6. Shell Programming and Scripting

sed imbed a tab

I'm using OpenBSD 4.3 & ksh (pdksh) default shell. I'm trying to use sed to insert a tab into a text file with no luck. $ sed 's/SusanAppleton/Susan\o011Appleton/' myFile.txt Susano011Appleton $ sed 's/SusanAppleton/Susan\tAppleton/' myFile.txt SusantAppletonI'm close to suicide here. Please... (9 Replies)
Discussion started by: na5m
9 Replies

7. Shell Programming and Scripting

sed: how to insert tab?

Hi, I'm using the following to insert lines into file: sed ${rowNr}i'\ first row\ second row\ third row\ ' file.txt How can I add tab in front of each added line? "\t" or actual TAB does not seem to work? Thanks! (2 Replies)
Discussion started by: Juha
2 Replies

8. UNIX for Dummies Questions & Answers

using Grep with a tab

how can i use grep to search a file with a tab, for example grep -l "Text<TAB>Text" *.txt (2 Replies)
Discussion started by: Adriel
2 Replies

9. UNIX for Dummies Questions & Answers

how to grep for blank records (space,tab,/n)?

I want to exclude (-v) blank records from a file before analysing it. I know I can use '^]$' for spaces and tabs but how do you look for lines that have nothing (/n or line feed) ? (2 Replies)
Discussion started by: Browser_ice
2 Replies

10. UNIX for Dummies Questions & Answers

grep tab

I want to grep "xxx(tab)iii" but dunno the way to do it. I've tried : grep "xxx\tiii" * , but it dont works. Is there anyone that can help me? :) (3 Replies)
Discussion started by: AkumaTay
3 Replies
Login or Register to Ask a Question