Sponsored Content
Top Forums Shell Programming and Scripting Remove all blank lines in shell or awk. Post 302246146 by cfajohnson on Monday 13th of October 2008 02:07:39 AM
Old 10-13-2008

Take your pick:

Code:
tr -s '\n' < abc.txt

grep -v "^$" abc.txt

sed '/^$/d' abc.txt

sed '/./!d' abc.txt

awk '/./' abc.txt

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Remove blank lines

¿How can i remove blank lines between all lines in a long text file? Example WrongFile.txt : Line 1 Line 2 Line 3 CorrectFile.txt : Line 1 Line 2 Line 3 Thanks in advance :confused: (4 Replies)
Discussion started by: osymad
4 Replies

2. Shell Programming and Scripting

Shell script: Remove blank lines

Hi gurus, I have this file with blank lines in it. How do i remove them in shell? I tried these commands but not working: sed '/^ *$/d' or sed '/^$/d' Anybody has a better idea pls? Also there are lines which starts with a single space, how do we remove the space in those lines?... (3 Replies)
Discussion started by: gholdbhurg
3 Replies

3. Shell Programming and Scripting

Awk to remove Blank lines in pipedelimited

Awk to remove Blank lines in pipedelimited Help me correct this. nawk -F"|" '{a=$0; gsub(FS, "",a); if(length(a)) print}' file1 nawk -F"|" '{gsub(FS, "",$0);if(length($0)) print}' file1 (4 Replies)
Discussion started by: pinnacle
4 Replies

4. Shell Programming and Scripting

remove blank lines

I have joined 2 files. Join command worked fine. but the result showing extra blank lines. I tried to remove blank spaces by using awk (-- -42 RS= ORS="\n\n" file.txt) and sed (sed '/^ *$/d' file.txt)commands but didn't remove any Any suggestions plz:D 123 tab ....... ......tab .......234... (3 Replies)
Discussion started by: repinementer
3 Replies

5. Shell Programming and Scripting

Remove blank lines

I really hope someone can help me with this. I have several php files from a forum that I run, that now for some reason have blank lines after every line. Is there an easy way to make a script that does the following: * If there are consecutive blank lines, delete all of them except one. * If... (9 Replies)
Discussion started by: KidCactus
9 Replies

6. Shell Programming and Scripting

remove blank lines and merge lines in shell

Hi, I'm not a expert in shell programming, so i've come here to take help from u gurus. I'm trying to tailor a csv file that i got to make it work for the LOAD FROM command. I've a datatable csv of the below format - --in file format xx,xx,xx ,xx , , , , ,,xx, xxxx,, ,, xxx,... (11 Replies)
Discussion started by: dvah
11 Replies

7. Shell Programming and Scripting

Delete blank lines, if blank lines are more than one using shell

Hi, Consider a file named "testfile" The contents of file are as below first line added for test second line added for test third line added for test fourth line added for test fifth line added for test (5 Replies)
Discussion started by: anil8103
5 Replies

8. Shell Programming and Scripting

How to remove blank lines

Hi, I am facing a problem related to removing blank lines from a text document. Input Error 17-05-2011 11:01:15 VisualSVN Server 2.1 1001 The following information was included with the event: line3 line4 Error 17-05-2011 11:00:25 VisualSVN Server 2.1 ... (13 Replies)
Discussion started by: mayursingru
13 Replies

9. UNIX and Linux Applications

remove all blank lines

When I 'vi' my test file I see some blank lines. However once I do :set list to display hidden characters, I see the empty lines literally like this: ^I$ How do I remove them? I cannot find a regex to match them. (3 Replies)
Discussion started by: alexsuv
3 Replies

10. Shell Programming and Scripting

Remove Blank lines in VI

Hi, Which option is used to remove blank lines in VI (AIX). ? Regards, Siva (6 Replies)
Discussion started by: ksgnathan
6 Replies
Text::Trim(3pm) 					User Contributed Perl Documentation					   Text::Trim(3pm)

NAME
Text::Trim - remove leading and/or trailing whitespace from strings VERSION
version 1.02 SYNOPSIS
use Text::Trim; $text = " important data "; $data = trim $text; # now $data contains "important data" and $text is unchanged # or: trim $text; # work in-place, $text now contains "important data" @lines = <STDIN>; rtrim @lines; # remove trailing whitespace from all lines # Alternatively: @lines = rtrim <STDIN>; # Or even: while (<STDIN>) { trim; # Change $_ in place # ... } DESCRIPTION
This module provides functions for removing leading and/or trailing whitespace from strings. It is basically a wrapper around some simple regexes with a flexible context-based interface. EXPORTS
All functions are exported by default. CONTEXT HANDLING
void context Functions called in void context change their arguments in-place trim(@strings); # All strings in @strings are trimmed in-place ltrim($text); # remove leading whitespace on $text rtrim; # remove trailing whitespace on $_ No changes are made to arguments in non-void contexts. list context Values passed in are changed and returned without affecting the originals. @result = trim(@strings); # @strings is unchanged @result = rtrim; # @result contains rtrimmed $_ ($result) = ltrim(@strings); # like $result = ltrim($strings[0]); scalar context As list context but multiple arguments are stringified before being returned. Single arguments are unaffected. This means that under these circumstances, the value of $" ($LIST_SEPARATOR) is used to join the values. If you don't want this, make sure you only use single arguments when calling in scalar context. @strings = (" hello ", " there "); $trimmed = trim(@strings); # $trimmed = "hello there" local $" = ', '; $trimmed = trim(@strings); # Now $trimmed = "hello, there" $trimmed = rtrim; # $trimmed = $_ minus trailing whitespace Undefined values If any of the functions are called with undefined values, the behaviour is in general to pass them through unchanged. When stringifying a list (calling in scalar context with multiple arguments) undefined elements are excluded, but if all elements are undefined then the return value is also undefined. $foo = trim(undef); # $foo is undefined $foo = trim(undef, undef); # $foo is undefined @foo = trim(undef, undef); # @foo contains 2 undefined values trim(@foo) # @foo still contains 2 undefined values $foo = trim('', undef); # $foo is '' FUNCTIONS
trim Removes leading and trailing whitespace from all arguments, or $_ if none are provided. rtrim Like trim() but removes only trailing (right) whitespace. ltrim Like trim() but removes only leading (left) whitespace. UNICODE
Because this module is implemented using perl regular expressions, it is capable of recognising and removing unicode whitespace characters (such as non-breaking spaces) from scalars with the utf8 flag on. See Encode for details about the utf8 flag. Note that this only applies in the case of perl versions after 5.8.0 or so. SEE ALSO
Brent B. Powers' String::Strip performs a similar function in XS. AUTHOR
Matt Lawrence <mattlaw@cpan.org> ACKNOWLEDGEMENTS
Terrence Brannon <metaperl@gmail.com> for bringing my attention to String::Strip and suggesting documentation changes. perl v5.10.1 2010-06-07 Text::Trim(3pm)
All times are GMT -4. The time now is 06:25 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy