Removing blank lines from a txt file
Hi all,
I was just wondering if there was a way to remove blank lines from a .txt file. I have been using the DHT22 sensor on my raspberry pi to collect temperature and humidity data. The data collected is stored in the txt file under the name 'my_data.txt'. However, between each recording there is a blank line. Is there a code which will allow me to move this data onto another txt file but without the blank lines in between? Thanks, Connor |
|
Try
Code:
sed '/^$/d' file |
Thanks! How would I use that code in order to move the data without the blank lines, into a new txt file called something like my_data2.txt?
Sorry to be a pain |
Please try and do some of the work. How would you normally redirect data to another file?
|
When I try to enter my code a get a syntax error stating there's something wrong with this line: sed '/^$/d' my_data.txt
What could be the reason for this? |
So to confirm, you are at a command prompt and typing the line shown?:
Code:
$ sed '/^$/d' my_data.txt Also, is the file from Windows? If so you may need to run it through dos2unix prior to running linux tools on it. |
The exact message is-
File "edit_script.py", line 3 Sed '/^$/d' my_data(copy).txt ^ SyntaxError: invalid syntax I am writing the script in leafpad on raspberry pi |
sed is lower case for a start. Also, this seems to be part of a python script, not only is this vital information but you cannot directly call sed from within python without using other commands.
lastly, you are writing the script in leafpad, but what was the txt file written with? |
Quote:
|
Yes, not winning my vote as someone who should continue to receive help
|
Quote:
|
I think you misunderstood David. I am not against helping the individual, but he has opened a second thread and claimed he came up with the sed shown by searching Google, see here and not only is this a blatant fib but it also goes against the LQ rules of reposting the same question.
So no, I am with you on the fact that this is not necessarily an easy topic for a beginner, but I am not impressed when someone tries to usurp our generous nature either. |
All times are GMT -5. The time now is 08:25 PM. |