csh script for deleting extra spaces in text file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting csh script for deleting extra spaces in text file
# 1  
Old 03-12-2009
csh script for deleting extra spaces in text file

I am new to scripting and I needed to know if there would be an easy way to delete extra spaces in a text file. I have a file with three rows with 22 numbers each, but there is extra spaces between the numbers when it gets output by this program AFNI that I am using. What script would help delete the extra spaces so that there is only one space between numbers? The thing is, the numbers aren't all evenly spaced in the rows....

Thanks in advance...

Megan

Below is an example of what I have, and what I would like....

I have:
0 0 0.999967 6.99001e-06 -0.0311094 0.854128 0.836092 0.834233 -0.85582 0.823927 0.550543 0.465525 0.515718 0.392239 -0.479025 -0.391751 -0.513501 -0.467562 -0.552394 -0.110216 0.110064 0.0316397
0 0 -0.00581784 -0.963206 0.608888 0.520062 0.177423 -0.428004 0.439036 0.162573 0.612435 0.883944 0.704232 0.291954 0.247972 0.710596 0.857074 0.726207 0.217247 -0.0147384 0.52374 0.936388
0 0 -0.00566925 0.268765 -0.792646 0.000969838 -0.519105 -0.347661 -0.273532 0.542876 0.567297 0.0439296 -0.487947 -0.872302 0.842048 0.584452 0.0417219 -0.503993 -0.804776 -0.993798 0.844738 0.349539

I'd like:
0 0 0.999967 6.99001e-06 -0.0311094 0.854128 0.836092 0.834233 -0.85582 0.823927 0.550543 0.465525 0.515718 0.392239 -0.479025 -0.391751 -0.513501 -0.467562 -0.552394 -0.110216 0.110064 0.0316397
0 0 -0.00581784 -0.963206 0.608888 0.520062 0.177423 -0.428004 0.439036 0.162573 0.612435 0.883944 0.704232 0.291954 0.247972 0.710596 0.857074 0.726207 0.217247 -0.0147384 0.52374 0.936388
0 0 -0.00566925 0.268765 -0.792646 0.000969838 -0.519105 -0.347661 -0.273532 0.542876 0.567297 0.0439296 -0.487947 -0.872302 0.842048 0.584452 0.0417219 -0.503993 -0.804776 -0.993798 0.844738 0.349539
# 2  
Old 03-12-2009

This will even work in csh, which is not recommended for scripting:

Code:
tr -s ' ' < FILE

# 3  
Old 03-12-2009
Thanks! It worked!

-Megan
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read variables from a text file for use in csh script

Hello, I have a text file (say, declarevars.txt) that contains multiple lines that are essentially meant to be variable declarations: set arr1 = (var1a var1b var1c) set arr2 = (var2a var2b var2c) . . . I want to be able to read this text file within a csh (sorry) script and have that... (2 Replies)
Discussion started by: arjaydj
2 Replies

2. UNIX Desktop Questions & Answers

To remove the extra spaces at the end of each line in a file

I have a file of about 10k records and eace line is having an extra space of 5 byte at the end.. Iwant to remove the extra spaces at the end of each line.. Can someone please help me out.. I tried using sed command and its not working... can someone please help me out. (3 Replies)
Discussion started by: rammohan
3 Replies

3. Shell Programming and Scripting

How can I stop the unix script from trimming extra spaces?

I have a file which contains certain records about users. the row length is always fixed to 205 characters. Now I want to read each record line from the file, substring some portion out of it and put into another file. But I have observed that my script is trimming the extra spaces I have used for... (4 Replies)
Discussion started by: Pramit
4 Replies

4. Shell Programming and Scripting

clear extra spaces and tabs in a file

Any help appreciated Thanks sample input: > (extra spaces&tabs in here) test1 (extra spaces&tabs in here) 123.123.123.123 (extra spaces&tabs in here) abc (extra spaces&tabs in here) 123 --- < (extra spaces&tabs in... (3 Replies)
Discussion started by: goofist
3 Replies

5. Shell Programming and Scripting

Deleting lines that contain spaces in a txt file

I need some help deleting lines in a file that contain spaces. Im sure awk or sed will work but i dont know much about those commands. Any help is appreciated :D (7 Replies)
Discussion started by: r04dw4rri0r
7 Replies

6. UNIX for Dummies Questions & Answers

deleting white spaces in a file

Hello Guys, I am a newbie to unix. I am having a requirement. Please help me for finding a solution for this, I am having a file as mentioned below: $ cat shank ackca acackac akcajc akcjkcja akcj ckcklc I want to delete all the white spaces in this file, I tried... (2 Replies)
Discussion started by: mraghunandanan
2 Replies

7. Shell Programming and Scripting

how can i pass parameter with spaces to csh script

Hello all i need to pass to my shell script parameter that looks like "2 3 3" inside the script i need to use this string that looks like this "2 3 3" but when i try to print the script im getting syntax error , this is my script : set s = $1 echo $s (1 Reply)
Discussion started by: umen
1 Replies

8. Shell Programming and Scripting

exporting number into .csv file in text form (no other extra charc) from shell script

I have written a k shell program which is executing a sql and exporting data in numeric form like 0412323444 into .csv file. the problem i am facing is that , the data is coming in excel formatted in scientific form like 4.1+E08,while my requirement is to store data as such 0412323444 in excel ( no... (5 Replies)
Discussion started by: Deepak_Rastogi
5 Replies

9. Shell Programming and Scripting

how to insert a extra line in a text file

how to insert a extra line in a text file using a sh command iam trying to think of a way to add a extra line but without deleting the whole text do anyone have any ideas (2 Replies)
Discussion started by: bhaviknp
2 Replies

10. Shell Programming and Scripting

Deleting end line spaces for along file

How can i clear all space characteres for a long file at the end of each line? (3 Replies)
Discussion started by: osymad
3 Replies
Login or Register to Ask a Question