retain negative value through sed command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting retain negative value through sed command
# 15  
Old 06-25-2011
[QUOTE=bshivali;302533865]
Quote:
Originally Posted by bshivali
Hi All

I have input like this "(49,076.25)" ,"(100,74,60)",-4,620.55
I need the otput as -49076.25,1007460,-4620.55

I used the below sed command..
sed -e ':a' -e 's/\("[^"][^"]*\),\([^"][^"]*"\)/\1\2/;ta' test | sed -e 's/\("[^,]*\)[,]\([^"]*"\)/\1\2/g' | sed 's/"//g' | sed 's/(\([0-9.][0-9.]*,\{0,1\}[0-9.]*\))/-\1/g' > new

I am getting almost 95 percent output as -49076.25,1007460,-4,620.55
But if you can see -4,620.55 the comma is not been removed

its only "(49,076.25)" ,"(100,74,60)",-4,620.55
previous quote by y gemici gives me null command on excution

i have concatenated like this

sed -e 's/\("[^,]*\)[,]\([^"]*"\)/\1\2/g' test | sed -e ':a' -e 's/\("[^"][^"]*\),\([^"][^"]*"\)/\1\2/;ta' | sed 's/,\|["()]//g;s/-/,&/;s/^/-/;s/ /,/'
> new

thanks in advance
where is null?
Code:
# sed 's/,\|["()]//g;s/-/,&/;s/^/-/;s/ /,/'

does this gets null? i dont think so..
which your sed version? and your platform?

if you want to use reference although easy sed command then you can try this Smilie
Code:
# sed 's/"(\([^ ]*\),\([^ ]*\))" *,"(\([^ ]*\),\([^ ]*\),\(.*\))",\(.*\),\(.*\)/-\1\2,\3\4\5,\6\7/' file
-49076.25,1007460,-4620.55

regards
ygemici

Last edited by ygemici; 06-25-2011 at 08:04 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sendmail K command regex: adding exclusion/negative lookahead to regex -a@MATCH

I'm trying to get some exclusions into our sendmail regular expression for the K command. The following configuration & regex works: LOCAL_CONFIG # Kcheckaddress regex -a@MATCH +<@+?\.++?\.(us|info|to|br|bid|cn|ru) LOCAL_RULESETS SLocal_check_mail # check address against various regex... (0 Replies)
Discussion started by: RobbieTheK
0 Replies

2. UNIX for Dummies Questions & Answers

Sed/awk to find negative numbers and replace with 1?

Greetings. I have a three column file, and there are some numbers in the second column that are <1. However I need all numbers to be positive, thus need to replace all those numbers with just one. I feel like there must be a simple way to use awk to find these numbers and sed to replace but can't... (5 Replies)
Discussion started by: Twinklefingers
5 Replies

3. Shell Programming and Scripting

Delete and retain some characters

Ive been trying to google and tried sed and awk. BUt still getting no exact formula. I would like to know how to parse this at: From: Compute Machin Appliance 3.2.9.10000 123456 To: Compute Machin Appliance 3.2.9.123456 (5 Replies)
Discussion started by: kenshinhimura
5 Replies

4. UNIX for Advanced & Expert Users

retain ownership

Hi, I have a script which transfers files/directories from one HP unix to another HP unix server using SCP but i need to retain ownership of files/folders same as source server my script is as follows cd /sasdata/TR_CNTO328/C0328T07/Dry_Run_1/Macros find . -type d -newer . -exec scp -pr {}... (6 Replies)
Discussion started by: tushar_spatil
6 Replies

5. Shell Programming and Scripting

how to retain zero

Hi everyone i have simple mathematical problem bash> echo date +%m bash> 03 bash> month=`date +%m` bash> lmonth=$month-1 bash> echo $lmonth bash>2 it gives me two but i want the answer of 02 please help me how to do this (6 Replies)
Discussion started by: aishsimplesweet
6 Replies

6. Shell Programming and Scripting

Need to retain particular rows

Hi All, I am in need of help to retain particular rows. I have a large file with 5 columns. Column 3 has signs like “=” “>” “<” and column 5 has values “nm” “%” or empty space. I need to keep only rows which have “=” in column 3 and “nm” in column 5. How can I do it in awk? Any help is greatly... (3 Replies)
Discussion started by: newpro
3 Replies

7. Shell Programming and Scripting

Loop with sed command to replace line with sed command in it

Okay, title is kind of confusion, but basically, I have a lot of scripts on a server that I need to replace a ps command, however, the new ps command I'm trying to replace the current one with pipes to sed at one point. So now I am attempting to create another script that replaces that line. ... (1 Reply)
Discussion started by: cbo0485
1 Replies

8. Shell Programming and Scripting

mv command to rename multiple files that retain some portion of the original file nam

Well the title is not too good, so I will explain. I need to move (rename) files using a simple AIX script. ???file1.txt ???file2.txt ???file1a.txt ???file2a.txt to be: ???renamedfile1'date'.txt ???renamedfile2'date'.txt ???renamedfile1a'date'.txt ???renamedfile2a'date'.txt ... (4 Replies)
Discussion started by: grimace15
4 Replies

9. Shell Programming and Scripting

Problem with sed and negative regexpr's

I have a file with various syntax that I'm try to run sed on to change over a specific regexp and having problems. I want to swap all instances of a token so long as the token isn't followed by either an alphanumeric character, an underscore, or an exclamation point. The test file looks like... (1 Reply)
Discussion started by: ericbmn1
1 Replies

10. Shell Programming and Scripting

how to retain leading zeros

Hi All, I am working with a fixed width file Forrmat. C1 Number (10,3) C2 Number (10,3) e.g. c1= 0000000100.000 c2= 0000000020.000 0000000100.0000000000020.000 I have to perform c1 - c2 . i.e. I want answer to be 0000000080.000. but I am loosing the leading zeros( only getting... (3 Replies)
Discussion started by: Manish Jha
3 Replies
Login or Register to Ask a Question