Removing whitespace from files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Removing whitespace from files
# 8  
Old 06-10-2003
vi yourfile
:%s/ /\%/g

does the job perfectly!
# 9  
Old 06-10-2003
Better for removing blank lines

Quote:
Originally posted by Kelam_Magnus
[B]My personal fav for removing blank lines...not your question... but I thought it still might be relevant.
Code:
grep -v ^$ file.in > file.out

^ designates the beginning of the line.
$ designates the end of the line.
But this only removes empty lines, not lines filled with spaces and tabs. Better:
Code:
awk 'NF > 0' file.in > file.out

# 10  
Old 06-10-2003
thanks for restating my post.... IF you will re-read the first line of my post, you will notice I did say that this portion only removes blank lines..

My second example is for removing blanks in a data file. Assuming that there is no blank lines at the end of the line. You can expand this to work with data files that have upto 9 fields...


Just trying to show that there are different examples that work depending on your file...
even though some are more encompassing than others...
# 11  
Old 06-10-2003
And another version by perl:
Code:
perl -pe "s/ /%/g" < initial.file > output.file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Find and removing the old files and zipping the files using shell script

Hi, I am trying to removing the old files which were older than 10 days and same g zipping the files using the shell script. script was return as follows. find /jboss7_homes/JBOSS7/SKYLIV??/SKYLIV??_CRM/jboss-eap-7.0/standalone/log -mtime +10 -type f | xargs rm -f find /cer_skyliv??/log... (6 Replies)
Discussion started by: venkat918
6 Replies

2. UNIX for Dummies Questions & Answers

Help in Removing the Old files

Hi Gurus, we are planning to clear the old log files based on the year and i need help on this and i searched in google and i came up with the scripts but i am stuck with this. (1) wroks fine How many files exist in based on the extension find -type f | sed -e 's/.*\.//' | sort | uniq... (1 Reply)
Discussion started by: SeenuGuddu
1 Replies

3. UNIX for Dummies Questions & Answers

Removing files

How do you delete/remove multiple files ? (5 Replies)
Discussion started by: nosuchluck
5 Replies

4. Shell Programming and Scripting

Removing whitespace issue

Hi, I have a file with rows like below delimited with pipe (|) I want to remove all the leading and trailing white space from each and every fields keeping the delimiter intact. I have tired this sed 's/*//g;s/*$//g' but the result is incorrect it is removing a whitespace from... (6 Replies)
Discussion started by: COD4
6 Replies

5. Shell Programming and Scripting

How to match (whitespace digits whitespace) sequence?

Hi Following is an example line. echo "192.22.22.22 \"33dffwef\" 200 300 dsdsd" | sed "s:\(\ *\ \):\1:" I want it's output to be 200 However this is not the case. Can you tell me how to do it? I don't want to use AWK for this. Secondly, how can i fetch just 300? Should I use "\2"... (3 Replies)
Discussion started by: shahanali
3 Replies

6. Shell Programming and Scripting

Help with removing files

i have a directory that have files that contains word "spam", how can i remove all those files which have word spam. This code help me in searching find ./ -type f -exec grep -l "spam" {} \; How i will add removing option with it. If some one have good suggestion regarding searching... (2 Replies)
Discussion started by: learnbash
2 Replies

7. Shell Programming and Scripting

Copy files listed in a text file - whitespace problem.

Hi, Say I have this text file <copy.out> that contains a list of files/directories to be copied out to a different location. $ more copy.out dir1/file1 dir1/file2 dir1/file3 "dir1/white space" dir1/file4 If I do the following: $copy=`more copy.out` $echo $copy dir1/file1... (4 Replies)
Discussion started by: 60doses
4 Replies

8. Shell Programming and Scripting

removing old files except configuration files and folders

Dear all, I want to remove files older than 2 months in the /home/member directory. But except the configuration files (like .bash_profile .config/ .openoffice/ .local/ .kde/ etc..) I have tried with the command find . -mtime +60 -wholename './.*' -prune -o -print -exec mv {} \; but it... (1 Reply)
Discussion started by: jamcalicut
1 Replies

9. Shell Programming and Scripting

removing whitespace from middle of file -help

I have a file in which I clean out a bunch of nonsense text as well as path information. What I end up with is something like the following: johnson.........................................................933 Where the periods represent the whitespace The file comes out originally with... (2 Replies)
Discussion started by: roninuta
2 Replies

10. UNIX for Dummies Questions & Answers

removing files

Hello all, I'd like to remove files which is returned by the following statement ls -l arch*.dbf|grep "`date|cut -c5-10`" (cut -c5-10 =Mar 20) To achive this,I tried the following statments but none worked .. rm < `ls -l arch*.dbf|grep "`date|cut -c5-10`"` rm `ls -l arch*.dbf|grep... (8 Replies)
Discussion started by: luft
8 Replies
Login or Register to Ask a Question