default blank line in end of file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting default blank line in end of file
# 1  
Old 10-07-2011
default blank line in end of file

Dear Experts,
I have spent my full day looking for the solution..Smiliebut could no resolved.

Here it goes:
I have a txt file say data.txt. The content is shown below:
**************
datav1
datav2
datav3

***********
I have shown the blank line knowingly. If I open this txt file using emacs, it shows this blank line (as cursor goes there)but this lines go away if I open it using vi editor.

For my purpose this line should either be removed [which mean the cursor should stop at the last line (datav3) only ] or I should put "#" there in the end space line.

I tried "sed". It does work well but not in my case. As it does not recognize this blank line.
with single file, this can be done manually. But I need to handle 50 such files.

any help would be greatly appreciated.
thanks
pooja..
# 2  
Old 10-07-2011
Can you post output of
Code:
cat -e data.txt

Please use code tags for the output. Here is the video tutorial explaining for to do it: https://www.unix.com/how-post-unix-li...code-tags.html
# 3  
Old 10-07-2011
Hi,
Please find the output here,
****************
[lxplus426] > cat -e data.txt
rfio:///castor/cern.ch/user/s/sudha/27Aug/data/datav1/data_10_1_Z8e.root$
rfio:///castor/cern.ch/user/s/sudha/27Aug/data/datav1/data_11_1_5ms.root$
rfio:///castor/cern.ch/user/s/sudha/27Aug/data/datav1/data_12_1_oAv.root$
rfio:///castor/cern.ch/user/s/sudha/27Aug/data/datav1/data_13_1_VCv.root$
[lxplus426] >
*****************

actually, the text shown here is the real text. I simplified this in the previous mail.
Hope it is clear.
thanks
pooja
# 4  
Old 10-07-2011
There is no empty line at the end of your file. If there was, the output would look like this:
Code:
solaris% cat -e data.txt 
rfio:///castor/cern.ch/user/s/sudha/27Aug/data/datav1/data_10_1_Z8e.root$
rfio:///castor/cern.ch/user/s/sudha/27Aug/data/datav1/data_11_1_5ms.root$
rfio:///castor/cern.ch/user/s/sudha/27Aug/data/datav1/data_12_1_oAv.root$
rfio:///castor/cern.ch/user/s/sudha/27Aug/data/datav1/data_13_1_VCv.root$
$

# 5  
Old 10-07-2011
Hi,
Sorry for not using code tags, I just saw the video.
Please find the code here. Strange is I get the same result even if I go there and remove that last line manually. Smilie
Still, I am stuck. The C++ code which read this text file duplicate the last entry if I do not remove the blank space manually.

Code:
PoojaSaxena@PoojaSaxena-PC ~
$ cat -e data.txt
rfio:///castor/cern.ch/user/s/sudha/27Aug/data/datav1/data_10_1_Z8e.root$
rfio:///castor/cern.ch/user/s/sudha/27Aug/data/datav1/data_11_1_5ms.root$
rfio:///castor/cern.ch/user/s/sudha/27Aug/data/datav1/data_12_1_oAv.root$
rfio:///castor/cern.ch/user/s/sudha/27Aug/data/datav1/data_13_1_VCv.root$

PoojaSaxena@PoojaSaxena-PC ~
$

I have to do it manually for 50 files, if I do not get a solution.SmilieSmilie
pooja..

---------- Post updated at 04:46 PM ---------- Previous update was at 04:38 PM ----------

Please find the code below. One of my friend told me the wayt to check if that line is removed or not is using cat command. And here is the output.

Firstly, I did not remove blank line manually, hence using cat the terminal prompt goes to new line.
Then I opened the file and did it manually and finally again opened it using cat. you can see that the terminal prompt is with the end of the text of the file.

Does it make sense..?? Smilie

Code:
[lxplus426]  /afs/cern.ch/user/p/pooja/scratch0/CMSSW/CMSSW_4_2_7_patch1/src/Analyzer/Analyser/AnalyserCode/data  > cat data.txt
rfio:///castor/cern.ch/user/s/sudha/27Aug/data/datav1/data_10_1_Z8e.root
rfio:///castor/cern.ch/user/s/sudha/27Aug/data/datav1/data_11_1_5ms.root
rfio:///castor/cern.ch/user/s/sudha/27Aug/data/datav1/data_12_1_oAv.root
rfio:///castor/cern.ch/user/s/sudha/27Aug/data/datav1/data_13_1_VCv.root
[lxplus426] /afs/cern.ch/user/p/pooja/scratch0/CMSSW/CMSSW_4_2_7_patch1/src/Analyzer/Analyser/AnalyserCode/data > op data.txt
[lxplus426]  /afs/cern.ch/user/p/pooja/scratch0/CMSSW/CMSSW_4_2_7_patch1/src/Analyzer/Analyser/AnalyserCode/data  > cat data.txt
rfio:///castor/cern.ch/user/s/sudha/27Aug/data/datav1/data_10_1_Z8e.root
rfio:///castor/cern.ch/user/s/sudha/27Aug/data/datav1/data_11_1_5ms.root
rfio:///castor/cern.ch/user/s/sudha/27Aug/data/datav1/data_12_1_oAv.root
rfio:///castor/cern.ch/user/s/sudha/27Aug/data/datav1/data_13_1_VCv.root[lxplus426]   /afs/cern.ch/user/p/pooja/scratch0/CMSSW/CMSSW_4_2_7_patch1/src/Analyzer/Analyser/AnalyserCode/data  >

Thanks again
pooja..
# 6  
Old 10-07-2011
Code:
grep -v "^$" < input > output

will remove blank lines.

If you're putting them into one giant list, then just
Code:
cat *.ext | grep -v "^$" > outfile

to pile them together and remove all blank lines.
# 7  
Old 10-08-2011
Hi,
It does not help. It does not help. Here is the piece of code:

Code:
[lxplus311] /afs/cern.ch/user/p/pooja/scratch0/CMSSW/CMSSW_4_2_7_patch1/src/Analyzer/Analyser/AnalyserCode/data > grep -v "^$" < data.txt > file.txt
[lxplus311] /afs/cern.ch/user/p/pooja/scratch0/CMSSW/CMSSW_4_2_7_patch1/src/Analyzer/Analyser/AnalyserCode/data > cat file.txt
rfio:///castor/cern.ch/user/s/sudha/27Aug/data/datav1/data_10_1_Z8e.root
rfio:///castor/cern.ch/user/s/sudha/27Aug/data/datav1/data_11_1_5ms.root
rfio:///castor/cern.ch/user/s/sudha/27Aug/data/datav1/data_12_1_oAv.root
rfio:///castor/cern.ch/user/s/sudha/27Aug/data/datav1/data_13_1_VCv.root
[lxplus311] /afs/cern.ch/user/p/pooja/scratch0/CMSSW/CMSSW_4_2_7_patch1/src/Analyzer/Analyser/AnalyserCode/data >

For me the litmus test is to do
Code:
 $cat file.txt

if prompt comes with text (in the same line), then only that blank lines goes away. As you can find in the above code this is not the case.

To make clear what I am saying, here is the Corrected code (corrected manually):
Code:
[lxplus311] /afs/cern.ch/user/p/pooja/scratch0/CMSSW/CMSSW_4_2_7_patch1/src/Analyzer/Analyser/AnalyserCode/data > cat data.txt
rfio:///castor/cern.ch/user/s/sudha/27Aug/data/datav1/data_10_1_Z8e.root
rfio:///castor/cern.ch/user/s/sudha/27Aug/data/datav1/data_11_1_5ms.root
rfio:///castor/cern.ch/user/s/sudha/27Aug/data/datav1/data_12_1_oAv.root
rfio:///castor/cern.ch/user/s/sudha/27Aug/data/datav1/data_13_1_VCv.root[lxplus311] /afs/cern.ch/user/p/pooja/scratch0/CMSSW/CMSSW_4_2_7_patch1/src/Analyzer/Analyser/AnalyserCode/data >

thnaks for prompt replies..
pooja..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Inserting a blank line at the end of a .txt file?

Hi there, I am having this problem: a) I am uploading a txt file from windows (notepad) with some Gaussian 09 command lines; b) Gaussian needs in certain command files, that those files have a blank line at the end of the file! c) I open the command file with vi and no blank line at the of... (2 Replies)
Discussion started by: luismga
2 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. UNIX for Dummies Questions & Answers

Add blank line to end of file

Alright, so I was looking around a bit on the forum before posting and still don't really understand so I figured I'd post my own question. I am appending two files using cat file_1.txt >> file_2.txt The problem is that I need a blank line in between the two different text files and it does... (2 Replies)
Discussion started by: cgagnon
2 Replies

4. Shell Programming and Scripting

appending a blank line for a group of files at the end

hi, i m having a group of files starting with name 'Itemdelete<timestamp>' . my requirment is to append a blank line at the end of files ,using unix in all the Itemdelete* files with a single unix command without using scripts.can any body put some light to this requiremnt. regards Angel (4 Replies)
Discussion started by: angel12345
4 Replies

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

6. Shell Programming and Scripting

how to add blank spaces at the end of every record in a file.

hi, Does anyone has any idea in adding few blank spaces at the end of every record in a file. Eg: file.txt Baby Boy Kim 1234 Baby Boy Vik 1334 Desired output:- output.txt Baby Boy Kim 1234 Baby Boy Vik 1334 I want to add 10 blank spaces at the end every record in file.txt (3 Replies)
Discussion started by: techmoris
3 Replies

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

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

9. Shell Programming and Scripting

Delete blank lines at the end of file

I am attempting to delete blank lines in my file and I've used this command: sed '/^$/d' $file > $file.fixed all this seems to do is copy the file and not delete the blank lines located at the end of the file. Any assistance would be greatly appreciated. (3 Replies)
Discussion started by: TL56
3 Replies

10. Shell Programming and Scripting

Blank Lines - End of file

Hi all I need to strip blank lines from the end of a file. I have searched and found topics on how to strip lines from the entirety of a file - however I need to limit this to only the last 3-4 lines. Any ideas? Thanks (4 Replies)
Discussion started by: saabir
4 Replies
Login or Register to Ask a Question