remove special character from a specific column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting remove special character from a specific column
# 1  
Old 05-26-2011
remove special character from a specific column

Hello ,

i have a text file like this :

Code:
A123   c12AB c32DD aaaa
B123    23DS  12QW bbbb
C123    2GR    3RG  cccccc

i want to remove the numbers from second and third column only.

i tried this :

Code:
perl -pe 's/[^A-Za-z\s]//g' file.txt > newfile.txt

but it will remove the number from all the file , but i want to keep the numbers in the first column,

thanks
# 2  
Old 05-26-2011
Code:
awk '{gsub("[0-9]*","",$1);gsub("[0-9]*","",$3)}1' infile.txt >newfile.txt

---------- Post updated at 12:57 PM ---------- Previous update was at 12:56 PM ----------

Code:
awk '{gsub("[0-9]*","",$2);gsub("[0-9]*","",$3)}1' infile.txt >newfile.txt

---------- Post updated at 01:00 PM ---------- Previous update was at 12:57 PM ----------

Alternately

Code:
awk '{gsub("[[:digit:]]",z,$2);gsub("[[:digit:]]",z,$3)}1' file.txt >newfile.txt

# 3  
Old 05-26-2011
thanks for you reply ,

it works , but it places a point(.) in front of new values in 2nd and 3rd column .

and can you please explain the command
# 4  
Old 05-26-2011
The command should not add a dot in front of new values in 2nd & 3rd columns...

Which plateform do you run?
Please copy/paste the command you have tried
# 5  
Old 05-26-2011
i used this :
Code:
awk '{gsub("[0-9]*","",$2);gsub("[0-9]*","",$3)}1' infile.txt >newfile.txt

and i have ubuntu 9.10 running on virtual box
# 6  
Old 05-26-2011
Could you please copy paste all that you have as input as well as result of the command ?

---------- Post updated at 01:34 PM ---------- Previous update was at 01:33 PM ----------

try the same without the wildcard :

Code:
awk '{gsub("[0-9]","",$2);gsub("[0-9]","",$3)}1' infile.txt >newfile.txt

These 2 Users Gave Thanks to ctsgnb For This Post:
# 7  
Old 05-26-2011
it works now , i just added also the point to be removed , and it works , thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Text to column starting/ending with special character in each row

Hello, Here is my text data excerpted from the webpage: input My target is to get: What i tried is: sed 's/.*\(connector\)/1/' input > output but all characters coming before the word "connector" are deleted which is not good for me. My question: (9 Replies)
Discussion started by: baris35
9 Replies

2. Shell Programming and Scripting

awk command to find total number of Special character in a column

How to find total number of special character in a column? I am using awk -f "," '$col_number "*$" {print $col_number}' file.csv|wc -l but its not giving correct output. It's giving output as 1 even though i give no special character? Please use code tags next time for your code and... (4 Replies)
Discussion started by: AjitKumar
4 Replies

3. Shell Programming and Scripting

Remove blank space and insert special character

Hi Folks, I have a huge data of the below format abc #apple 1200 06/23 ghj #orange 1500 06/27 uyt #banana 2300 05/13 efg #vegetable 0700 04/16 After first 3 letters, i have 9 spaces and after fruit there are no specific fixed space, but it varies... (4 Replies)
Discussion started by: jayadanabalan
4 Replies

4. Shell Programming and Scripting

Remove the first character from the fourth column only if the column has four characters

I have a file as follows ATOM 5181 N AMET K 406 12.440 6.552 25.691 0.50 7.37 N ATOM 5182 CA AMET K 406 13.685 5.798 25.578 0.50 5.87 C ATOM 5183 C AMET K 406 14.045 5.179 26.909 0.50 5.07 C ATOM 5184 O MET K... (14 Replies)
Discussion started by: hasanabdulla
14 Replies

5. Shell Programming and Scripting

Remove some special ascii character

Hello I have this special caracter after retreving rows from sql server: "....spasses: • Entrem al valort 6050108002811 • El donem..." I would like a sed command to remove it..or just know it's ascii code in order to replace it into my sql sentence.. Hope some one knows how to do that.... (7 Replies)
Discussion started by: ldiaz2106
7 Replies

6. Shell Programming and Scripting

sed or tr to remove specific group of special characters

Hi, I have a input of the form: ..., word1, word2, word3... I want out put of the form word1, word2, word3 I tried echo '..., word1, word2, word3...' | tr -d '...,' but that takes out the commas in the middle too so I get word1 word2 word3 but I want the commas in the middle. ... (3 Replies)
Discussion started by: forumbaba
3 Replies

7. Shell Programming and Scripting

Remove special character ($) from file names

Hello I've searched here and on the 'net for examples of a script or command line function that will remove the $ character from all file names only that can be done within the directory that contains the file names - which are all html files. ie, I have a directory that contains html files... (6 Replies)
Discussion started by: competitions
6 Replies

8. Shell Programming and Scripting

remove special character from a textfile

Can any one plse help me writing shell script to removing some special character pattern (like / > -------, / > / > ------- etc....as shown below) from the text file ASAP. / > ------- <tag-normalization tag-name="EXECSERVPRODUCT" read-only="false" part="body"> ... (3 Replies)
Discussion started by: bkc
3 Replies

9. Shell Programming and Scripting

Remove box like special character from end of string

Hi All, How to remove a box like special character which appears at the end of a string/line/record. I have no clue what this box like special character is. It is transparent square like box. This appears in a .DAT file at the end of header. I'm to compare a value in header with a parameter.... (16 Replies)
Discussion started by: Qwerty123
16 Replies
Login or Register to Ask a Question