Removing blank lines not working


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Removing blank lines not working
# 8  
Old 08-19-2012
Pls post a hexdump/octal dump of your input file so the guessing can be replaced by analysing.
These 3 Users Gave Thanks to RudiC For This Post:
# 9  
Old 08-19-2012
OK. If you really want to get rid of blank lines (lines containing zero or more space and/or tab characters terminated by a newline character) rather than empty lines (lines that only contain the terminating newline character), there are still LOTS of ways to do it. Two are:
Code:
grep '[^        ]' text

where the characters between the square brackets are <circumflex>, <space>, and <tab>. or with sed instead of grep:
Code:
sed '/^[        ]*$/d' text

where the characters between the square brackets are just <space>, and <tab>.
This User Gave Thanks to Don Cragun For This Post:
# 10  
Old 08-19-2012
For all we know, there could be control characters in the data, in which case none of the solutions provided will work.

RudiC has given the best advice yet.

Regards,
Alister
This User Gave Thanks to alister For This Post:
# 11  
Old 08-19-2012
Quote:
Originally Posted by MaindotC
This is really weird...I modified my sed expression:
Code:
for i in $(cat txt)
do
echo $i | sed 's/|/ /g;s/ SEARCHTERM$//g;s/ /\r\n/g;/^[[:space:]]*$/ d;/^$/d'
done

I tried adding the -E but I got a lot of error messages - not sure why that was included. So most of the whitespaces are gone...there used to be 5 whitespaces, now there is 1. So based on this information I have to assume there's something freaky going on with my input file?

---------- Post updated at 03:10 PM ---------- Previous update was at 03:09 PM ----------



Close, but I'm still getting some whitespaces. Possibly an issue with the input file? Anyway I can view special, hidden chars?

More than likely because what the code does is if there is no fields it is skipped.

Last edited by methyl; 08-19-2012 at 06:53 PM.. Reason: fix code tag
# 12  
Old 08-19-2012
@MaintdotC
Yet again, please post what Operating System and version you are running. This really matters - expecially if it happens to be MACOS or Cygwin.

Please post sample input data using this sed command which is designed to make control codes visible and make white space visible. In your case, the line terminators could be important.
Code:
sed -n l filename

Please then post sample expected output data to match you sample input data, with an expanation of the process if it is not obvious.


Footnote: Please explain what you think your sed command does? Where did you find pipe characters in unix group file? What is SEARCHSTRING for? Why "\r\n" (looks like trying to convert to MSDOS format to me)?
Others have posted valid commands to remove white space.

The script posted contains fundamental design issues which we can address once we see the sample data.
This User Gave Thanks to methyl For This Post:
# 13  
Old 08-20-2012
The sed command you listed does produce some slashes between the text of the input used for my script but for some reason I am now receiving the desired output. I didn't make a backup of my script and accidentally removed it, so when I wrote it again this morning I didn't even put in a sed expression to remove whitespaces and it works for some reason. Not sure what happened between last night and today but I'm good now - thanks all for your support.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To check Blank Lines, Blank Records and Junk Characters in a File

Hi All Need Help I have a file with the below format (ABC.TXT) : ®¿¿ABCDHEJJSJJ|XCBJSKK01|M|7348974982790 HDFLJDKJSKJ|KJALKSD02|M|7378439274898 KJHSAJKHHJJ|LJDSAJKK03|F|9898982039999 (cont......) I need to write a script where it will check for : blank lines (between rows,before... (6 Replies)
Discussion started by: chatwithsaurav
6 Replies

2. UNIX for Advanced & Expert Users

Delete blank spaces and blank lines in a file

Hi Gurus, Somebody can say me how to delete blank spaces and blank lines in a file unix, please. Thank you for advanced. (10 Replies)
Discussion started by: systemoper
10 Replies

3. Shell Programming and Scripting

Removing blank lines

Hi, my input file is like this I want to remove the blank line. "/home/rit/sandbox/garuda/data/test/woman/T_RITK_F0008_ML_100080039.lab" r a N e l a k sh a m . "/home/rit/sandbox/garuda/data/test/woman/T_RITK_F0008_ML_100070453.lab" a v a s (4 Replies)
Discussion started by: sreejithalokkan
4 Replies

4. Shell Programming and Scripting

Removing blank lines from a file

Hi All, How do i remove continuos blank lines from a file. I have a file with data: abc; def; ghi; jkl; mno; pqr; In the above file, there are two blank lines. I want to remove, one out of them. My output should look like: (2 Replies)
Discussion started by: raosr020
2 Replies

5. 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

6. UNIX for Dummies Questions & Answers

Removing blank lines in a file

Hi I have a text file that has blank lines at different places. How to remove all the blank lines in a file? Thanks Ashok (3 Replies)
Discussion started by: ashok.k
3 Replies

7. Shell Programming and Scripting

PERL: removing blank lines from multiple files

Hi Guru's , I have a whole bunch of files in /var/tmp that i need to strip any blank lines from, so ive written the following script to identify the lines (which works perfectly).. but i wanted to know, how can I actually strip the identified lines from the actual source files ?? my... (11 Replies)
Discussion started by: hcclnoodles
11 Replies

8. Shell Programming and Scripting

Removing blank lines from comma seperated and space seperated file.

Hi, I want to remove empty/blank lines from comma seperated and space seperated files Thanks all for help (11 Replies)
Discussion started by: pinnacle
11 Replies

9. Shell Programming and Scripting

removing duplicate blank lines

Hi, how to remove the blank lines from the file only If we have more than one blank line. thanks rameez (8 Replies)
Discussion started by: rameezrajas
8 Replies

10. Shell Programming and Scripting

Removing Blank Lines

Hi i have the below lines from a file 7538 PRGRP450800PERSONAL SOAP AND BATH ADDITIV 7036 PRGRP450800PERSONAL SOAP AND BATH ADDITIV 7036 PRGRP450800PERSONAL SOAP AND BATH ADDITIV 7036... (3 Replies)
Discussion started by: dhanamurthy
3 Replies
Login or Register to Ask a Question