The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Replace space ecearund Shell Programming and Scripting 9 04-02-2009 05:03 AM
Cannot replace null with space rikxik Shell Programming and Scripting 1 03-06-2009 12:13 AM
replace space by _ ruben.rodrigues Shell Programming and Scripting 6 01-21-2009 11:27 AM
replace space with new line dakid Shell Programming and Scripting 2 06-03-2008 09:47 PM
replace tab with space avnerht UNIX Desktop for Dummies Questions & Answers 1 06-13-2002 08:30 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-23-2009
kshuser kshuser is offline
Registered User
  
 

Join Date: Oct 2009
Posts: 30
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 (permalink)  
Old 10-23-2009
research3 research3 is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 88
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 (permalink)  
Old 10-23-2009
kshuser kshuser is offline
Registered User
  
 

Join Date: Oct 2009
Posts: 30
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 View Post
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 (permalink)  
Old 10-23-2009
research3 research3 is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 88
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
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:05 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0