removing lines without text


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting removing lines without text
# 1  
Old 12-15-2011
removing lines without text

How do I remove line that do not contain text, but that do contain tabs?

I have tried the command
Code:
cat file | awk NF

but that doesn't work when the lines contain tabs (and spaces).

I have also tried:
Code:
cat file | sed '/^$/d'

# 2  
Old 12-15-2011
Try sed '/^[:space:]*$/d'.
This User Gave Thanks to CarloM For This Post:
# 3  
Old 12-15-2011
You want to remove empty lines?

Code:
awk '!/^[ \t]*$/' input_file

--ahamed
This User Gave Thanks to ahamed101 For This Post:
# 4  
Old 12-15-2011
the "empty" lines are still there. They contain tabs and/or spaces. I have no idea how to remove them
# 5  
Old 12-15-2011
Code:
 
grep -v . inputfile > outputfile

This User Gave Thanks to itkamaraj For This Post:
# 6  
Old 12-15-2011
Code:
perl -ne '(!/^\s+/)&&print' inputfile

Quote:
Originally Posted by locoroco
the "empty" lines are still there. They contain tabs and/or spaces. I have no idea how to remove them
@locoroco: ahmed101's solution works perfectly.

@CarloM: sed '/^[[:space:]]*$/d'

Last edited by balajesuri; 12-15-2011 at 06:51 AM..
This User Gave Thanks to balajesuri For This Post:
# 7  
Old 12-15-2011
Paste the output of cat -A input_file

Are you telling that the file is unchanged? Of course it will not get modified.

Code:
awk '!/^[ \t]*$/' input_file > out_file
 
#or use sed -i to change the file inline
 
sed '/^[[:space:]]*$/d' input_file

--ahamed

Last edited by ahamed101; 12-15-2011 at 07:07 AM..
This User Gave Thanks to ahamed101 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Selecting text on multiple lines, then removing a beginning and end patterns

I have a file similar to the below. I am selecting only the paragraphs with @inlineifset. I am using the following command sed '/@inlineifset/,/^ *$/!d; s/@inlineifset{mrg, @btpar{@//' $flnm >> $ofln This produces @section Correlations between seismograms,,,,}} ... (5 Replies)
Discussion started by: Danette
5 Replies

2. Shell Programming and Scripting

Removing multiple lines from input file, if multiple lines match a pattern.

GM, I have an issue at work, which requires a simple solution. But, after multiple attempts, I have not been able to hit on the code needed. I am assuming that sed, awk or even perl could do what I need. I have an application that adds extra blank page feeds, for multiple reports, when... (7 Replies)
Discussion started by: jxfish2
7 Replies

3. Shell Programming and Scripting

Joining broken lines and removing empty lines

Hi - I have req to join broken lines and remove empty lines but should NOT be in one line. It has to be as is line by line. The challenge here is there is no end of line/start of line char. thanks in advance Source:- 2003-04-34024|04-10-2003|Claims|Claim|01-13-2003|Air Bag:Driver;... (7 Replies)
Discussion started by: Jackceasar123
7 Replies

4. UNIX for Dummies Questions & Answers

Removing PATTERN from txt without removing lines and general text formatting

Hi Everybody! First post! Totally noobie. I'm using the terminal to read a poorly formatted book. The text file contains, in the middle of paragraphs, hyphenation to split words that are supposed to be on multiple pages. It looks ve -- ry much like this. I was hoping to use grep -v " -- "... (5 Replies)
Discussion started by: AxeHandle
5 Replies

5. Shell Programming and Scripting

Removing md5sum lines stored in text file

Hello. I'm writing a script where every file you create will generate a md5sum and store it into a text file. Say I create 2 files, it'll look like this in the text file: d41d8cd98f00b204e9800998ecf8427e /helloworld/saystheman d41d8cd98f00b204e9800998ecf8427e /helloworld/test I... (3 Replies)
Discussion started by: batarangs_
3 Replies

6. UNIX for Dummies Questions & Answers

Removing trailing lines at the end of a text file

How do you remove trailing empty lines at the end of a text file? Thanks! (3 Replies)
Discussion started by: evelibertine
3 Replies

7. Shell Programming and Scripting

Removing empty lines(space) between two lines containing strings

Hi, Please provide shell script to Remove empty lines(space) between two lines containing strings in a file. Input File : A1/EXT "BAP_BSC6/07B/00" 844 090602 1605 RXOCF-465 PDTR11 1 SITE ON BATTERY A2/EXT... (3 Replies)
Discussion started by: sudhakaryadav
3 Replies

8. UNIX for Dummies Questions & Answers

removing multiple lines of text in a file

Hi, I'm trying to remove multiple lines of text based off a series of different words and output it to a new file The document contains a ton of data but i want to delete any line that has the following mx1.rr.biz.com or ns2.ri.biz.com i tried using grep -v filename "mx1.rr.biz.com" >... (3 Replies)
Discussion started by: spartan22
3 Replies

9. Solaris

removing particular lines ending with a .cnt extension in a text file

I have a text file with rows of information (it is basically a ls command information(o/p from ls command)) I need to remove the lines ending with a .cnt extension and keep the lines ending with .zip extension, how to accomplish this. I also only need the date,size and name of the file from every... (2 Replies)
Discussion started by: ramky79
2 Replies

10. Shell Programming and Scripting

Removing lines in a text file.

Here is my problem I'm hoping you guru's can help me figure out. I have a text file that contains comma delimited columns. What I'm looking to do is see if the 24th column on each row in the file contains a value (not null), and then write/append that line to a different file. I've been... (4 Replies)
Discussion started by: WABonnett
4 Replies
Login or Register to Ask a Question