removing whitespace from middle of file -help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting removing whitespace from middle of file -help
# 1  
Old 10-17-2007
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 the columns of name and hits left and right justified respectively. Since the names are of a variable length and the number on the right is also variable length, how would I go about removing the whitespace in the middle? I am newbie to sed, but rapidly falling in love with it.

Thanks in advance
# 2  
Old 10-17-2007
One way with awk:
Code:
 awk '{print $1,$2}' oldfile > newfile

This assumes just two values, it won't work with:
blah blah blah 933

If that is the case then:
Code:
awk '{printf("%s", $1)
         for (i=2; i<NF; i++) {printf(" %s", $i)}
         printf("\n"); ' oldfile > newfile

# 3  
Old 10-23-2007
Am not sure about ur Requiement!!!!!!!!!!!!!!

Hope this wil do ur task?

sed 's/ *//g' filename


Regards,
Anand
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Subsituting contents of entire file to middle of another file using awk

Hi I have a data file 'File2' consisting of 105670 lines. I want to copy and paste 17928 lines from 'File1' to 'File2' but I want to place it in between lines 21 and 17950 of 'File2'. How do I do it in awk? For example- File A has 5 lines X Y 1 2 3 4 5 6 7 8 9 and File B has A b... (1 Reply)
Discussion started by: ananyob
1 Replies

2. Shell Programming and Scripting

Subsituting contents of entire file to middle of another file using awk

Hi I have a data file 'File2' consisting of 105670 lines. I want to copy and paste 17928 lines from 'File1' to 'File2' but I want to place it in between lines 21 and 17950 of 'File2'. How do I do it in awk? For example- File A has 5 lines X Y 1 2 3 4 5 6 7 8 9 and File B has A b... (1 Reply)
Discussion started by: ananyob
1 Replies

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

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

5. Shell Programming and Scripting

Minimum whitespace separated CSV file generation

Hi, I have a flat text file consisting of rows (each field separated by '|') from a table. e.g; NSW|Gulliver Travels|236||5000|BW This has to be converted to the following format NSW "Gulliver Travels" 236 5000 BW No data field has to be left as a blank character so that we have... (6 Replies)
Discussion started by: vharsha
6 Replies

6. Shell Programming and Scripting

How to process from middle of a file?

Hi There. I have a file like this . a nnnn sds b ssss fdefd c sdfd dsfd sdfds ... ... Summary t1 t2 t3 t4 s1 s2 s3 s4 f1 f2 f3 f4 .. How to use awk to begin process this file from the line that contains "Summary"? Thanks! louis (12 Replies)
Discussion started by: javacore
12 Replies

7. Shell Programming and Scripting

How to insert text into first line of the file and middle of the file?

Script 1 Pre-requisites Create a file with x amount of lines in it, the content of your choice. Write a script that takes two arguments. The first being a line of text, the second being your newly created file. The script should take the first argument and insert it into the very top (the... (3 Replies)
Discussion started by: ali hussain
3 Replies

8. Shell Programming and Scripting

appending to sed output of one file into the middle of file

hi, i have a file file1 file2 ----------- ----------------- aa bbb ccc 111 1111 1111 ddd eee fff 222 3333 4444 ggg hhh... (5 Replies)
Discussion started by: go4desperado
5 Replies

9. Shell Programming and Scripting

rename file with whitespace embedded

Say a directory contains files 1) "file name 1.xxx" 2) "file name2.yyy" 3) etc Using a cshell script, is there a way to (1)search for all files that contain " " in the filename and then (2)rename the files so that you replace the whiitespace " " with a "_". First problem I run into is... (6 Replies)
Discussion started by: orlando47
6 Replies

10. Shell Programming and Scripting

Removing whitespace from files

Hello, I was wondering if there was a way to write a script to do the following: turn a file that contains: 1234 Kevin Smith 12:09 456235 1234 John Robger 12:09:09 353657 into: 1234%Kevin%Smith%12:09%456235... (10 Replies)
Discussion started by: kevin80
10 Replies
Login or Register to Ask a Question