How to use the sub command to replace a <space> between two numbers


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to use the sub command to replace a <space> between two numbers
# 1  
Old 02-25-2012
How to use the sub command to replace a <space> between two numbers

Hi I have file which stores dates.

Code:
2008-09-12|2008-09-12<space1>00:00:12|<space2>2008-09-12

Some one please help me on how should I use the sub command to replace only the space which has numbers on both sides.

Expected output
Code:
2008-09-12|2008-09-1200:00:12|<space2>2008-09-12

--
Thanks
# 2  
Old 02-25-2012
I'm unaware of a sub command, however sed should do what you want.
Try the following
Code:
sed 's/\([0-9]\) \([0-9]\)/\1\2/g' dates_file.dat

# 3  
Old 02-25-2012
something like this ..

Code:
echo "2008-09-12|2008-09-12 00:00:12| 2008-09-12" | sed 's/[0-9] [0-9]//g'

# 4  
Old 02-25-2012
sed

Quote:
Originally Posted by codemaniac
something like this ..

Code:
echo "2008-09-12|2008-09-12 00:00:12| 2008-09-12" | sed 's/[0-9] [0-9]//g'

Hi,

This is will substitue the space and as well as the prefix and suffix of that space as blank. so you have to get those numbers and use it in replace part. As Skrynesaver did in previous post.


Cheers,
RangaSmilie
# 5  
Old 02-25-2012
Thanks all...SED wrk...Just was wondering if it was possible using awk's "sub" function...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove space before numbers in delimited file

Hi, I have a file which looks like this FORD|1333-1| 10000100010203| 100040507697|0002|356.45|5555| SSSSY|KKKKM|1000005|10| N096|10043| C987 I need the output to look like this FORD|1333-1|10000100010203|100040507697|0002|356.45|5555| SSSSY|KKKKM|1000005|10| N096|10043| C987 The leading... (8 Replies)
Discussion started by: wahi80
8 Replies

2. UNIX for Dummies Questions & Answers

How can I replace the lines that start with a star and replace it with numbers start from 1?

I need to replace the (*) in the fist of a list with numbers using sed for example > this file contain a list * linux * computers * labs * questions to >>>> this file contain a list 1. linux 2. computers 3. labs 4. questions (7 Replies)
Discussion started by: aalbazie
7 Replies

3. Shell Programming and Scripting

Help awk/sed: putting a space after numbers:to separate number and characters.

Hi Experts, How to sepearate the list digit with letters : with a space from where the letters begins, or other words from where the digits ended. file 52087mo(enbatl) 52049mo(enbatl) 52085mo(enbatl) 25051mo(enbatl) The output should be looks like: 52087 mo(enbatl) 52049... (10 Replies)
Discussion started by: rveri
10 Replies

4. Shell Programming and Scripting

SED - insert space at the beginning of line and multi replace command

hi I am trying to use SED to replace the line matching a pattern using the command sed 'pattern c\ new line ' <file1 >file 2 I got two questions 1. how do I insert a blank space at the beginning of new line? 2. how do I use this command to execute multiple command using the -e... (5 Replies)
Discussion started by: piynik
5 Replies

5. UNIX for Dummies Questions & Answers

insert white space between numbers

Hello all, I have a file with several lines like this: (1,1) (4,10) (8,23) (17, 4) (6,8) etc. and I need this: ( 1 , 1 ) ( 4 , 10 ) ( 8 , 23 ) ( 17 , 4 ) ( 6 , 8 ) How do I insert a space between the left parenthesis and the first number, between the first number and the comma,... (2 Replies)
Discussion started by: MDeBiasse
2 Replies

6. Shell Programming and Scripting

replace numbers in records

hello every one I have file with following records begin ASX120016719 ASX190006729 ASX153406729 ASX190406759 ASX180006739 end for each record there is ASX word then 9 digits after it (NO spaces included) what i want is to : 1- skip ASX 2-skip first 2 digits after ASX word... (16 Replies)
Discussion started by: neemoze
16 Replies

7. UNIX for Dummies Questions & Answers

Inserting space between numbers

Are there any one-liners or short codes to separate 4-digit numbers into 2? For example, input.txt: 1234 5678 3091 2851 Output.txt: 12 34 56 78 30 91 28 51 (7 Replies)
Discussion started by: pxalpine
7 Replies

8. Infrastructure Monitoring

SNMP disk space - inaccurate numbers

on the remote server that im running the snmp command against, below is the information about the specific directory i'm concerned about: SIZE USED AVAIL 673G 483G 157G can someone explain to me why snmp is telling me the size of this filesystem is 176399584? ... (5 Replies)
Discussion started by: SkySmart
5 Replies

9. UNIX for Dummies Questions & Answers

Replace US numbers with European numbers

hey, I have a file with numbers in US notation (1,000,000.00) as well as european notation (1.000.000,00) i want all the numbers to be in european notation. the numbers are in a text file, so to prevent that the regex also changes the commas in a sentence/text i thought of: sed 's/,/\./'... (2 Replies)
Discussion started by: FOBoy
2 Replies

10. 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
Login or Register to Ask a Question