Issue deleting blank line from a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Issue deleting blank line from a file
# 1  
Old 03-28-2014
[Solved] Issue deleting blank line from a file

I'm trying to delete the blank lines from the file $Sfile. tried the below set of commands. Both are giving the same error (: bad interpreter: No such file or directory)

Code:
awk 'NF > 0' $Sfile > $Tfile
cat $Tfile

Code:
sed -i '/^$/d' $Sfile
cat $Sfile

Not sure if there's any other problem with the program. But without the above scripts, the program is working fine. But I need this logic to be put, in order to remove the blank lines, as it is causing some issues.

Please help me.
# 2  
Old 03-28-2014
Code:
echo $Sfile | sed -i.BKUP '/^$/d'

This User Gave Thanks to in2nix4life For This Post:
# 3  
Old 03-28-2014
How do I write the output of this to a file?

---------- Post updated at 06:27 PM ---------- Previous update was at 06:22 PM ----------

With the below script also, I'm getting the same error

Code:
echo $Sfile | sed -i.BKUP '/^$/d'

Code:
: bad interpreter: No such file or directory

---------- Post updated at 06:31 PM ---------- Previous update was at 06:27 PM ----------

Below is the complete set of code :

Code:
#!/bin/sh
#
Sfile=/u01/scripts/Sfile.log
Pfile=/u01/scripts/Pfile.log
Tfile=/u01/scripts/Tfile.log

cat /dev/null > $Sfile
grep -v '-' $Pfile > $Tfile
grep -v 'PRCSINSTANCE' $Tfile > $Sfile
echo $Sfile | sed -i.BKUP '/^$/d'

# 4  
Old 03-28-2014
Code:
Sfile=/path/filename
sed -i.BKUP '/^$/d' $Sfile

-i option is in place replacement, sed will take backup of your original file as "filename.BKUP"
This User Gave Thanks to pravin27 For This Post:
# 5  
Old 03-28-2014
Thanks Pravin. It is still giving the error :

Code:
: bad interpreter: No such file or directory

Please let me know if I'm missing anything in the code.
# 6  
Old 03-28-2014
Please explain the complete logic of what you want the script to do as in the initial posting you just mentioned removing blank lines from the filename contained in a variable.
# 7  
Old 03-28-2014
Usually that would mean your hashbang is wrong. I would think /bin/sh is correct though...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Deleting the last non blank line from a file

PGW|PGW_CDR_|2017-06-23 141946|2017-07-17 131633|2017-08-21 PGW|PGW_CDR_|2017-06-23 141946|2017-07-17 131633|2017-08-21 PGW|PGW_CDR_|2017-06-23 141946|2017-07-17 131633|2017-08-21 PGW|PGW_CDR_|2017-06-23 141946|2017-07-17 131633|2017-08-21 PGW|PGW_CDR_|2017-06-23 141946|2017-07-17... (6 Replies)
Discussion started by: swathi reddy1
6 Replies

2. Shell Programming and Scripting

In a file, replace blank line by the last line not blank above

Dear All, In a CSV file, say that a given column has been extracted. In that column, information is missing (i.e. blank lines appear). I would like to replace the blank lines by the last valid line (not blank) previously read. For example, consider the extract below: 123 234 543 111... (7 Replies)
Discussion started by: bagvian
7 Replies

3. Shell Programming and Scripting

Issue deleting all lines (having a specific string) in a file

I'm trying to create a script. There are 2 files - fileA.log & fileB.log fileA.log has the below data : aaaa cccc eeee fileB.log has the below data : cjahdskjah aaaa xyz jhaskjdhas bbbb abc ajdhjkh cccc abc cjahdskjah ... (7 Replies)
Discussion started by: Pandee
7 Replies

4. Shell Programming and Scripting

deleting blank lines ONLY at the end of the file

Hi Guys, I have a quetion which was already discussed in the forum, but for some reason all approches suggested fail for me. I have a file which have blank lines at the body of the text as well as at the end. I need to delete ONLY blank lines at the end. Unfortunatly the approach below does not... (5 Replies)
Discussion started by: aoussenko
5 Replies

5. Shell Programming and Scripting

SQL sorrting issue, and unwanted blank line above heading

Hi, I am running a shell script on Compaq Tru64 UNIX V5.1A. I have attached the shill script with the sql script it is calling to extract some data(hyp_dta_Extr.sql), and the results. I need the file to be tab delimited. (please note that I have renamed hyp_dta_Extr.sql to hyp_dta_Extr.txt to... (1 Reply)
Discussion started by: dazz
1 Replies

6. Shell Programming and Scripting

deleting blank line and row containing certain words in single sed command

Hi Is it possible to do the following in a single command /usr/xpg4/bin/sed -e '/rows selected/d' /aemu/CALLAUTO/callauto.txt > /aemu/CALLAUTO/callautonew.txt /usr/xpg4/bin/sed -e '/^$/d' /aemu/CALLAUTO/callautonew.txt > /aemu/CALLAUTO/callauto_new.txt exit (1 Reply)
Discussion started by: aemunathan
1 Replies

7. Solaris

deleting blank space in beginning of line in vi

How can we delete all the blank spaces in the beginning of some lines in a text in vi? Thanks, (2 Replies)
Discussion started by: Pouchie1
2 Replies

8. Shell Programming and Scripting

Replace two blank line with a single blank line

Hi Guys, I have a file in which each set of records are separated by two blank line. I want to replace it with a single blank line. Can you guys help me out? Regards, Magesh (9 Replies)
Discussion started by: mac4rfree
9 Replies

9. Shell Programming and Scripting

how to replace a line in file with blank line

Hi I nned cmd to which will help me to replace a line in file with blank line e.g. file1 a b c d e after running cmd I shud get file1 b c d e (5 Replies)
Discussion started by: tarunn.dubeyy
5 Replies

10. Shell Programming and Scripting

Deleting the blank line in a file and counting the characters....

Hi, I am trying to do two things in my script. I will really appreciate any help in this regards. Is there a way to delete a last line from a pipe delimited flat file if the last line is blank. If the line is not blank then do nothing..... Is there a way to count a word that are starting... (4 Replies)
Discussion started by: rkumar28
4 Replies
Login or Register to Ask a Question