Removing Space at the end of file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Removing Space at the end of file
# 1  
Old 03-02-2005
Data Removing Space at the end of file

Hi....

I have a situation...I have a data file...that has space(an extra row with no data) at the end of file. I am trying to remove that spaces only if the file has a space at the end of file and if there is no space I don't want to do anything.

Can you please help me in this regards.

Thanks
Raj
rkumar28
# 2  
Old 03-02-2005
Quote:
Originally Posted by rkumar28
Hi....

I have a situation...I have a data file...that has space(an extra row with no data) at the end of file. I am trying to remove that spaces only if the file has a space at the end of file and if there is no space I don't want to do anything.

Can you please help me in this regards.

Thanks
Raj
a sample input with spaces to be deleted marked as '_', pls
and a desired output, pls.
# 3  
Old 03-02-2005
Quote:
Originally Posted by rkumar28
Hi....

I have a situation...I have a data file...that has space(an extra row with no data) at the end of file. I am trying to remove that spaces only if the file has a space at the end of file and if there is no space I don't want to do anything.

Can you please help me in this regards.

Thanks
Raj
something like this?
Code:
sed -e '$s/[ ][ ]*$//g' file

# 4  
Old 03-03-2005
Using sed we can do as,

Code:
sed -e '${/^$/d}' <filename>

It will check the last line of a file and if it is null then it will be deleted.

HTH.
# 5  
Old 03-03-2005
Quote:
Originally Posted by muthukumar
Using sed we can do as,

Code:
sed -e '${/^$/d}' <filename>

It will check the last line of a file and if it is null then it will be deleted.

HTH.
'null line' != 'line with blanks'
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Removing pipe and space in a file

Hi , I have a file which is like below. The file record is separated by | as delimiter. I want to remove the first and last | in the file and also I want to remove the spaces in the columns. Original File |3464114 |10 | REPORT|CA| 1|0|4825400|0|213167| 939396524| Expected:... (3 Replies)
Discussion started by: arunkumar_mca
3 Replies

2. Shell Programming and Scripting

Gawk --- produce the output in pattern space instead of END space

hi, I'm trying to calculate IP addresses and their respective calls to our apache Server. The standard format of the input is HOST IP DATE/TIME - - "GET/POST reuest" "User Agent" HOST IP DATE/TIME - - "GET/POST reuest" "User Agent" HOST IP DATE/TIME - - "GET/POST reuest" "User Agent" HOST... (2 Replies)
Discussion started by: busyboy
2 Replies

3. Shell Programming and Scripting

Add words in beginning , end after removing a word in a file

My file has the entries like below... /dev/sds /dev/sdak /dev/sdbc /dev/sdbu I want to make the file like below echo 1 > /sys/block/sds/device/rescan echo 1 > /sys/block/sdak/device/rescan echo 1 > /sys/block/sdbc/device/rescan echo 1 > /sys/block/sdbu/device/rescan (2 Replies)
Discussion started by: saravanapandi
2 Replies

4. UNIX for Dummies Questions & Answers

Removing empty lines at the end of a Tab-delimited file

I'm trying to remove all of the empty lines at the end of a Tab delimited file. They have no data just tabs. I've tried may things, here are a couple: sed /^\t.\t/d File1 > File2 sed /^\t{44}/d File1 > File2 What am I missing? (9 Replies)
Discussion started by: SirHenry1
9 Replies

5. Shell Programming and Scripting

Removing blank space in file

TT0000013101257 | JCJMMUJMMUB018 ... (0 Replies)
Discussion started by: sususa
0 Replies

6. UNIX for Dummies Questions & Answers

Removing trailing lines at the end of a text file

How do you remove trailing empty lines at the end of a text file? Thanks! (3 Replies)
Discussion started by: evelibertine
3 Replies

7. Shell Programming and Scripting

Add a space at end of file

Hi I guess this is very simple.... I want to add a space at the last line in a file. The space has to be the last charachter on the last line, not at a new line. Anyone ?? (7 Replies)
Discussion started by: disel
7 Replies

8. UNIX for Dummies Questions & Answers

Removing ^@ chanracter fromthe end of Linux file

Hi, I have a Linux file which has content as shown below 2,Latest Event in RFP_EVENT match Lastest event in Source PRH_RQ_REQUEST,Failed... (3 Replies)
Discussion started by: bhuvanas
3 Replies

9. UNIX for Dummies Questions & Answers

Removing ^@ character at the end own belowof Linux file

Hi, I have a Linux file which has content as sh (0 Replies)
Discussion started by: bhuvanas
0 Replies

10. UNIX for Dummies Questions & Answers

removing a character and addending to end in each line in a file

HI i am having a file this (sys19:pnlfct:/pfact/temp>) cat temp_sand 1234567890 1234567890 1234567890 1234567890 I want to make this file as (sys19:pnlfct:/pfact/temp>) cat temp_sand 1456789023 1456789023 1456789023 1456789023 just take the 2nd and 3rd position and put it... (5 Replies)
Discussion started by: arunkumar_mca
5 Replies
Login or Register to Ask a Question