exchange values in a table - exchange numbers


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting exchange values in a table - exchange numbers
# 1  
Old 10-12-2012
exchange values in a table - exchange numbers

Hello all,

This is a bit simple but I cannot do it! I have a big table of values between 0 and 1. some cells have NA instead of having any value.

I want to exchange all values with "1" and write "0" for all "NA" .

for changing "NA" to zero I used sed:
Code:
sed -i 's/NA/0/g' input.txt

But I have no clue for changing all numbers to 1.

I appreciate if you can help me with this.

---------- Post updated at 06:54 PM ---------- Previous update was at 06:47 PM ----------

I have managed to do it with this:

Code:
sed -e 's/[0-9]*\.[0-9]*/1/g' -e 's/NA/0/g' in.txt > out.txt

I hope it's correct! Smilie
# 2  
Old 10-12-2012
Well, it will also turn . into 0, so in place of * you might want to say \{1,9\}, but for well behaved input, it is ok.
# 3  
Old 10-15-2012
you're right DGPickett! I haven't thought about it! Actually my input is rather big so I have no clue if it's well behaved! Smilie Gonna do what you recommended! Thanks!
# 4  
Old 10-15-2012
Yes, I often wish for the meta-version '+' that a few regex flavors have, like * but for one or more.

Limiting length correctly is very important since by default regex is aggressive (greedy -- biggest string that will fit). I get a lot of mileage out of '[^sep]' in place of '.' Some pattern matching tools let you choose lazy or aggressive, like the ksh ${name#pattern} is lazy and ${name##pattern} is aggressive (# is pound on the nose, % is take your percentage in the end).
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. AIX

Exchange one server to another

Hi people, In my work i have 2 P595 server (P595A and P595B) i need to exchange one server from P595A to P595B and one from P595B to P595A, i know the best way to do this is make a mksysb copy of the system and restore it on another but, in this process i dont need to exchange all the server,... (4 Replies)
Discussion started by: anonymouzz
4 Replies

2. AIX

Relay to Exchange Server

AIX 5.3 Domain: domainna Exchange Server: ex05.domainname.com Our emails that are generated from Unix going to the "outside world" are now being rejected by most hosts. The current relay is listed as user@domainna. Here is a snippet from the log... 1356561:Aug 21 08:04:05 domainna... (0 Replies)
Discussion started by: andrewsc
0 Replies

3. Windows & DOS: Issues & Discussions

exporting exchange information

Hey all, I have teh job of exporting all the information for around 500 e-mail addresses from exchange into something like a excel sheet. I was pretty quiet one afternoon last week (and bore) so I added them to my adddresses book then exported them to excel. But I now have a problem, it does... (0 Replies)
Discussion started by: woofie
0 Replies

4. UNIX for Dummies Questions & Answers

Mail Exchange Server

I've got a question regarding setting up mail between two unix boxes. Is it possible to setup two boxes conected via a hub and allow them to send mail using the Netscape Messenger. I know that I can be done so using the UNIX sendmail but I need to connect them via Messenger as my ultimate goal is... (0 Replies)
Discussion started by: GlockCW
0 Replies

5. UNIX for Dummies Questions & Answers

mailing from unix -> exchange

Hello, I want to mail from Unix 4.3 (on an RS/6000) to my Microsoft exchange server (5.5). When I trie : mail -v erikr@domain.nl < /directory/file I get the following error: ^Cserverone:/etc >WARNING: The local host name (serverone) does not have a domain; fix$jnconfig ... (7 Replies)
Discussion started by: Erik Rooijmans
7 Replies

6. Windows & DOS: Issues & Discussions

Connecting to an Exchange Server

Hi, I have installed Redhat 7.3 on my desktop at work and was wondering whether I can set up my mail in KDE(Kmail, Mozilla Mail etc) to connect to a microsoft exchange server. Thanks for any help! (2 Replies)
Discussion started by: camerja1
2 Replies

7. UNIX for Dummies Questions & Answers

mail exchange

Hi everyone I am setting up my own web hosting and dns server - have got all the dns and web server things sorted out. I am wondering if anyone knows what I need to do to enable my customers to have their own pop and smtp access under their own domains which they host with me. I have two ip... (2 Replies)
Discussion started by: alwayslearningunix
2 Replies
Login or Register to Ask a Question