Removing spaces at particular position


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Removing spaces at particular position
# 1  
Old 07-09-2006
Removing spaces at particular position

I have a file with delimiter ~

ABC~12~43~TR ~890~poi~YU ~56~65

What I want is to remove spaces from column 4,7 and other columns as it is
So, the final file becomes

ABC~12~43~TR~890~poi~YU~56~65
# 2  
Old 07-09-2006
This may help you.
# 3  
Old 07-09-2006
$ echo "ABC~12~43~TR ~890~poi~YU ~56~65" | sed 's/ //g'
ABC~12~43~TR~890~poi~YU~56~65
# 4  
Old 07-10-2006
Quote:
Originally Posted by Hitori
$ echo "ABC~12~43~TR ~890~poi~YU ~56~65" | sed 's/ //g'
ABC~12~43~TR~890~poi~YU~56~65
This will remove all the spaces
I am looking to remove spaces at particular position
Let me change the example
If I have

ABC~12~43~TR ~890~poi~YU ~56~65 ~BNP

I want is
ABC~12~43~TR~890~poi~YU~56~65~BNP
# 5  
Old 07-10-2006
Then it's better to use awk
# 6  
Old 07-10-2006
Quote:
Originally Posted by Hitori
Then it's better to use awk
ok, how do I do it in awk?
# 7  
Old 07-10-2006
This works in bash - is that what you were looking for?
Code:
line="ABC~12~43~TR ~890~poi~YU ~56~65 ~BNP"
IFS="~" read _1 _2 _3 _4 _5 _6 _7 _8 _9 _10 <<<"$line"
echo "${_1}~${_2}~${_3}~${_4/ /}~${_5}~${_6}~${_7/ /}~${_8}~${_9}~${_10}"

Only fields 4 and 7 remove the space.

If that's not it, can you restate what you're trying to do?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How do I replace a string in file that is in a certain position with spaces?

I am trying to replace the string in position 26 through 35 of the data file with 10 spaces and I want the remaining file to stay as is, the record length is over 900 characters? I am trying to use the AWK and substr but I am not getting it formatted correctly. Before... (6 Replies)
Discussion started by: fnwine1500
6 Replies

2. Linux

Removing a character at specific position in a column

Hi, I have a file like this (about 8 columns in total, this being the 2nd column) gi_49482297_ref_YP_039521.1_ gi_49482297_ref_YP_039521.1_ gi_49482315_ref_YP_039539.1_ gi_49482315_ref_YP_039539.1_I want to remove the _ at the end of the line. And at later stages I would want to replace the... (5 Replies)
Discussion started by: Syeda Sumayya
5 Replies

3. Shell Programming and Scripting

Removing blanks, spaces

I have pipe separated file with lots of blank spaces. After using sed -e 's/ *| */|/g' this command ,its giving me output as TT0000013101640| HCAMBLAMCNB010|Jul 3 2012 11:14AM| HARYANA| Bangali Mohalla | TCL-UBR|9368040005|9355264655|9218509220|NULL ... (5 Replies)
Discussion started by: sususa
5 Replies

4. Shell Programming and Scripting

Remove the spaces at the end of a line starting from a fixed position

I want to remove the trailing spaces at the end of each line starting from a particular position(using ksh script). For example, in the attached file, I want to remove all the spaces starting from the position 430 till the end. The space has to be removed only from the 430th position no matter in... (3 Replies)
Discussion started by: Suryaaravindh
3 Replies

5. Shell Programming and Scripting

Removing 0 from a specific position - if it exists

I have a file that I need to parse using a script. The dates in the file are displayed in the format: Mar 2, 2011 9:09:31 PM I have tried using the date command %e and %l but it pads an extra space for the day and hour if they are single digits. So this I used a normal date command: ... (6 Replies)
Discussion started by: crazyideas
6 Replies

6. Shell Programming and Scripting

using awk removing newline and specific position

Hello Friends, Input File looks as follows: >FASTA Header1 line1 line2 line3 linen >FASTA Header2 Line1 Line2 linen >FASTA Header3 and so on ....... Output: Want something as: >FASTA Header1 line1line2line3linen >FASTA Header2 (5 Replies)
Discussion started by: Deep9000
5 Replies

7. Shell Programming and Scripting

Removing blank spaces, tab spaces from file

Hello All, I am trying to remove all tabspaces and all blankspaces from my file using sed & awk, but not getting proper code. Please help me out. My file is like this (<b> means one blank space, <t> means one tab space)- $ cat file NARESH<b><b><b>KUMAR<t><t>PRADHAN... (3 Replies)
Discussion started by: NARESH1302
3 Replies

8. UNIX for Dummies Questions & Answers

Removing spaces...

Hey, I'm using the command from this thread https://www.unix.com/unix-dummies-questions-answers/590-converting-list-into-line.html to convert vertical lines to horzontal lines. But I need to remove the spaces that is created. Unfortunately I can't figure out where the space is in the code.. I... (2 Replies)
Discussion started by: lost
2 Replies

9. Shell Programming and Scripting

removing spaces

hey.. i had a problem with the unix command when i want to remove the white spaces in a string..i guess i cud do it with a sed command but i get an error when i give space in the square brackets.. string="nh hjh llk" p=`echo $string | sed 's/ //g'` i donno how to give space charater and... (2 Replies)
Discussion started by: sahithi_khushi
2 Replies

10. UNIX for Dummies Questions & Answers

removing spaces from variables?

I stored results like this VAR=`wc -l < ls.txt` But the value of the wc gave me a padded number. How do I strip the padding from $VAR? Do you think I could use SED? Except instead of a file input, have a variable redirection input? (2 Replies)
Discussion started by: yongho
2 Replies
Login or Register to Ask a Question