![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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!! |
|
||||
|
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.. |
|
||||
|
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:
Last edited by Franklin52; 10-23-2009 at 02:37 PM.. Reason: Please use code tags!! |
|
||||
|
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 |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|