remove white space from specific columns in text file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting remove white space from specific columns in text file
# 1  
Old 05-10-2011
remove white space from specific columns in text file

Hello

i have a text file like this:

Code:
1 AB AC AD EE
2 WE TR YT WW
3 AS UY RF YT

the file is bigger , but that's an example of the data

what i want to do is to merge all columns together except the first one,
it will become like this :
Code:
1 ABACADEE
2 WETRYTWW
3 ASUYRFYT

how this can be done ??

thanks in advance
# 2  
Old 05-10-2011
use this sed script (assuming there is no : in the data)

Code:
 
s/ /:/
s/ //g
s/:/ /

# 3  
Old 05-10-2011
hello , thanks for your reply , but it did not worked
# 4  
Old 05-10-2011
Another way:
Code:
awk '{s=$1;gsub($1 FS,x);$1=$1;print s FS $0}' OFS= file

This User Gave Thanks to Franklin52 For This Post:
# 5  
Old 05-10-2011
thanks a lot Franlin52 it worked
# 6  
Old 05-10-2011
An infile replacement:
Code:
# cat file
1 AB AC AD EE
2 WE TR YT WW
3 AS UY RF YT

Code:
# perl -ni -e '($a,$b)=/^(\S+\s)(.*)/;$b=~s/\s//g;print $a.$b."\n";' file

Code:
# cat file                                                               
1 ABACADEE
2 WETRYTWW
3 ASUYRFYT

This User Gave Thanks to Klashxx For This Post:
# 7  
Old 05-10-2011
i have another question concerning this data set , should i ask it here ? or open another thread??
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove of white space when you have multiple column

i have file in which i want to remove white space from each column where ever it exist there is white space at the end of line. i know how to remove white space if i have only 1 column, but i have multiple columns and white space can be in any column. sed 's/ *$//' file ath-miRf10005-akr... (5 Replies)
Discussion started by: mirwasim
5 Replies

2. Shell Programming and Scripting

Add specific text to columns in file by sed

What is the proper syntax to add specific text to a column in a file? Both the input and output below are tab-delineated. What if there are multiple text/fields, such as /CP&/2 /CM&/3 /AA&/4 Thank you :). sed 's/*/Index&/1' del.txt.hg19_multianno.txt > matrix.del.txt (4 Replies)
Discussion started by: cmccabe
4 Replies

3. Shell Programming and Scripting

Remove white space and duplicate headers

I have a file called "dsout" with empty rows and duplicate headers. DATE TIME TOTAL_GB USED_GB %USED --------- -------- ---------- ---------- ---------- 03/05/013 12:34 PM 3151.24316 2331.56653 73.988785 ... (3 Replies)
Discussion started by: Daniel Gate
3 Replies

4. Shell Programming and Scripting

Remove unwanted white space

Hi, I have a very big file 25GB with information present in it like $ head ind_stats update index statistics pfirm001.dbo.Office using 200 values go ... (11 Replies)
Discussion started by: sam05121988
11 Replies

5. UNIX for Dummies Questions & Answers

Adding tags to a specific column of a space delimited text file

I have a space delimited text file with two columns. I would like to add NA to the first column of the text file. Input: 19625 10.4791768259 19700 10.8146489183 19701 10.9084026759 19702 10.9861346978 19703 10.9304364984 Output: NA19625 10.4791768259 NA19700 10.8146489183... (1 Reply)
Discussion started by: evelibertine
1 Replies

6. UNIX for Dummies Questions & Answers

How do you view specific columns from a space delimited text file?

I have a space delimited text file with 1,000,000+ columns? I would only like to view specific ones (let's say through 1:10), how can I do that? Thanks! (3 Replies)
Discussion started by: evelibertine
3 Replies

7. UNIX for Dummies Questions & Answers

Deleting columns from a space delimited text file

I have a space delimited text file with 1,000,000+ columns and 100 rows. I want to delete columns 2 through 5 (2 and 5) included from the text file. How do I do that? Thanks. (3 Replies)
Discussion started by: evelibertine
3 Replies

8. Homework & Coursework Questions

Read text, handle white space

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: The problem would be to make the program tolerate the white space and still read the string of characters. the... (1 Reply)
Discussion started by: mgyeah
1 Replies

9. Shell Programming and Scripting

Remove white space at the beginning of lines

Hi! I store some data obtained with grep or awk in a file. The problem is that some lines have white space at the begining : line1 line2 line3 I use something like grep WORD INFILE >> OUTFILE awk >> OUTFILE I would love if it were possible to remove the white whitout parsing the... (4 Replies)
Discussion started by: tipi
4 Replies

10. Shell Programming and Scripting

Sh scripting problem, matching specific white space

Hey, I'm desperately in need of a solution to a seemingly easy problem. How can I match a specific number of spaces and replace them. As in, I have a file that instead of being broken into parts by new lines is broken into parts via 500+ spaces. How can I replace any grouping of more than 400... (7 Replies)
Discussion started by: Dickalicious
7 Replies
Login or Register to Ask a Question