replace space with + and - as negative only


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting replace space with + and - as negative only
# 1  
Old 10-23-2009
replace space with + and - as negative only

I have a file file1.dat with the following lines
Code:
22885068900000652 B86860003OLFXXX592123320081227
22885068900000652 B86860003ODL-Sp592123420081227
22885068900000652-B94030001ODL-Ch592123520081227
23666483030000653-B94030001ODL-Ch000000120081227
23797049900000654-E71060001OLFXXX000000220081227
23699281320000655 E71060002OLFXXX000000320081227

i want to get the output from the above file file1.dat what is the syntax for this.

Code:
22885068900000652+B86860003OLFXXX592123320081227
22885068900000652+B86860003ODL-Sp592123420081227
22885068900000652-B94030001ODL-Ch592123520081227
23666483030000653-B94030001ODL-Ch000000120081227
23797049900000654-E71060001OLFXXX000000220081227
23699281320000655+E71060002OLFXXX000000320081227

can someone help me on this.

Last edited by Franklin52; 10-23-2009 at 02:36 PM.. Reason: Please use code tags!!
# 2  
Old 10-23-2009
run sed command

Code:
sed 's/ /+/g' file.dat



---------- Post updated at 08:50 AM ---------- Previous update was at 08:49 AM ----------

output:

Code:
user@net:~$ sed 's/ /+/g' file
22885068900000652+B86860003OLFXXX592123320081227
22885068900000652+B86860003ODL-Sp592123420081227
22885068900000652-B94030001ODL-Ch592123520081227
23666483030000653-B94030001ODL-Ch000000120081227
23797049900000654-E71060001OLFXXX000000220081227
23699281320000655+E71060002OLFXXX000000320081227
user@net:~$


Last edited by research3; 10-23-2009 at 07:17 PM..
# 3  
Old 10-23-2009
replace space with + and - as negative only

right now i am using this way but i am getting only the 3 rows which replaces the space to + but then why i am not getting the existing negative rows in the file.dat file
Code:
grep ' ' $DATADIR/file.dat|sed s/\ /\+/g > $DATADIR/out_file.txt
 
22885068900000652+B86860003OLFXXX592123320081227
22885068900000652+B86860003ODL-Sp592123420081227
23699281320000655+E71060002OLFXXX000000320081227

I want the result with all the rows in the file.
Code:
22885068900000652+B86860003OLFXXX592123320081227
22885068900000652+B86860003ODL-Sp592123420081227
22885068900000652-B94030001ODL-Ch592123520081227
23666483030000653-B94030001ODL-Ch000000120081227
23797049900000654-E71060001OLFXXX000000220081227
23699281320000655+E71060002OLFXXX000000320081227


Quote:
Originally Posted by research3
run sed command

Code:
sed 's/ /+/g' file.dat

---------- Post updated at 08:50 AM ---------- Previous update was at 08:49 AM ----------

output:

Code:
user@net:~$ sed 's/ /+/g' file
22885068900000652+B86860003OLFXXX592123320081227
22885068900000652+B86860003ODL-Sp592123420081227
22885068900000652-B94030001ODL-Ch592123520081227
23666483030000653-B94030001ODL-Ch000000120081227
23797049900000654-E71060001OLFXXX000000220081227
23699281320000655+E71060002OLFXXX000000320081227
ovis@q45:~$


Last edited by Franklin52; 10-23-2009 at 02:37 PM.. Reason: Please use code tags!!
# 4  
Old 10-23-2009
in my example
Code:
sed 's/ /+/g' file > $DATADIR/out_file.txt

the sed command will be replaced all blank characters in all of the rows not only in 3 rows!!
The negative lines will not changed in this case.
Therefore I'm not undertand your issue, the result is the same or I'm wrong?

cat $DATADIR/out_file.txt

22885068900000652+B86860003OLFXXX592123320081227
22885068900000652+B86860003ODL-Sp592123420081227
22885068900000652-B94030001ODL-Ch592123520081227
23666483030000653-B94030001ODL-Ch000000120081227
23797049900000654-E71060001OLFXXX000000220081227
23699281320000655+E71060002OLFXXX000000320081227
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

In a row, replace negative sign and find minimum value among four columns

Hi Friends, I have an input file like this chr1 100 200 1 2 3 4 chr1 150 200 4 5 6 7 chr2 300 400 9 6 7 1 chr2 300 410 -10 21 -11 13 chr3 700 900 -21 -22 130 165 Now, my output file is chr1 100 200 1 chr1 150 200 4 chr2 300 400 1 chr2 300 410 10 chr3 700 900 21 Remove... (5 Replies)
Discussion started by: jacobs.smith
5 Replies

3. Shell Programming and Scripting

Replace space with empty

Hi All, My Input is: 111.121 23212121 121.231 12678878 My output should be 111.12123212121 121.23112678878 in each row i need to replace that perticular space with empty. 8th position in the file for all rows. Please help me in this case .. Thanks (7 Replies)
Discussion started by: raju4u
7 Replies

4. UNIX for Dummies Questions & Answers

replace %20 with space

Hi, I need torename filenames with %20 to space in a batch wise.Can anyone help me please. Need it badly Eg. English%20Brochure%20002-1 to be replace to English Brochure 002-1 Thanks a lot Please use and tags when posting code, data or logs etc. to preserve formatting... (8 Replies)
Discussion started by: umapearl
8 Replies

5. Programming

Replace one space with nothing

hi, d o g e v o l i want a perl command for the above string which should change to the below dog evol replace one space with nothing and two spaces with one space. Thanks, Amey (3 Replies)
Discussion started by: ameyrk
3 Replies

6. Shell Programming and Scripting

Replace every other space

I'd like a sed command to replace every other space in my file. File: 0 1 0 3 0 2 0 5 Want: 01 03 02 05 Does anyone have any ideas? (9 Replies)
Discussion started by: peanuts48
9 Replies

7. Shell Programming and Scripting

Replace long space to become one space?

Hi, i have the log attached. Actually i want the long space just become 1 space left like this : Rgds, (12 Replies)
Discussion started by: justbow
12 Replies

8. Shell Programming and Scripting

Replace space

Hai masters, If a file contains content of 2000 lines, from which i need to remove the first n characters or first n spaces from each line of the file. If suppose to remove n characters or first n spaces from a single line means, just use the command nx. But from the above scenario,... (9 Replies)
Discussion started by: ecearund
9 Replies

9. Shell Programming and Scripting

replace space by _

Hi I need to know how I change the spaces by _ in folders and filder founded by find ex. find . -name "* *" -exec echo {} \; ./test space ./test space/new file.txt ./test space/new file ./test space/untitled folder ./test space/untitled folder/new fileruben ./Backup/backup/Image... (6 Replies)
Discussion started by: ruben.rodrigues
6 Replies

10. Shell Programming and Scripting

replace space with new line

i have a file named as templist which looks like this: i want to translate spaces to a new line so that the file would look like this im using sed with this sed -e 's/" "/\n/' templist > templist.out but it doesn't work. can someone please help me. (2 Replies)
Discussion started by: dakid
2 Replies
Login or Register to Ask a Question