How i can add via preg replace dot after numbers ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How i can add via preg replace dot after numbers ?
# 1  
Old 03-11-2017
How i can add via preg replace dot after numbers ?

So lets say i have file my_birthday.402.zip ho it can became my_birthday.4.0.2.zip

Thank you Smilie
# 2  
Old 03-11-2017
The expensive way, easy to remember using GNU sed:
Code:
sed 's/[0-9]\B/&./g'

Code:
var=my_birthday.402.zip
echo "$var" | sed 's/[0-9]\B/&./g'





--
or using shell grammar, complicated but more efficient, if it is always 3 digits:
Code:
var=my_birthday.402.zip
tmpvar=${var%[0-9]*}
echo "${var%[0-9][0-9]*}.${tmpvar#"${var%[0-9][0-9]*}"}.${var#*[0-9][0-9]}"


Last edited by Scrutinizer; 03-11-2017 at 05:37 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Ommit the numbers or any characters only at 8th columns after the dot (.).

Ommit the numbers or any characters only at 7th or 8th columns after the dot (.) . Since the group column has 1 and 2 spaces. Thanks -rw-r--r--. 1 user1 domain users 619 2017-04-13 16:16:50.284598383 +0000 aa drwxr-xr-x. 2 root root 6 2017-05-08... (8 Replies)
Discussion started by: invinzin21
8 Replies

2. Shell Programming and Scripting

Replace null values with dot using awk

Using awk I am trying to replace all blank or null values with a . in the tad delimited input. I hope the awk is close. Thank you :). input name test sam 1 liz 2 al 1 awk awk 'BEGIN{FS=OFS="\t"}{for(i=1;++i<NF;)$i=$i?$i:"."}1'input awk 'BEGIN { FS =... (6 Replies)
Discussion started by: cmccabe
6 Replies

3. Shell Programming and Scripting

sed - search and replace whole string which contains dot

Hello. I would like to search exactly "string1.string2.string3" and replace it by "new_string1.new_string2.new_string3" And I would like to search exactly "string2.string3" and replace it by "new_string2.new_string3" And I would not found in the result : "string1.new_string2.new_string3"... (3 Replies)
Discussion started by: jcdole
3 Replies

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

5. Shell Programming and Scripting

Awk/sed - add space between dot and letter

I need to change . into . so that e.g. A.Jbecomes A. JI have tried sed 's/\./\.\ /g' but that didn't work. (9 Replies)
Discussion started by: locoroco
9 Replies

6. Shell Programming and Scripting

Replace dot with semicolon in PERL

Hi, I have a file in PERL in the following pattern filename| 06-Dec-11 03.04.14.000000 PM filename1| 06-Dec-11 05.05.14.000000 PM I need to replace .(dot) with :(semicolon) in the timestamp value of the file How can this be done. Any help will be appreciated Thanks in advance (5 Replies)
Discussion started by: irudayaraj
5 Replies

7. Shell Programming and Scripting

How to replace quote symbol(") and dot(.) with some other values!!

Hi , I have below input file 1.order number is useful. 2.vendor_id is produced. 3.the vandor name is "malawar". I want output file like 1. order number is useful. 2. vendor_id is produced. 3. the vandor name is VmalawarV. in input file line number 1.order number there is no... (4 Replies)
Discussion started by: vinothsekark
4 Replies

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

9. Shell Programming and Scripting

Greping numbers with dot in it

Hi, I wanted to create a script what would take two numbers out of two files and add them together, but I got stuck with greping numbers what have a dot in it. So far I have grepped the two lines what include the numbers I need (from both files) to a third file and from that file I try to... (7 Replies)
Discussion started by: mario8eren
7 Replies

10. Shell Programming and Scripting

Replace path in a file with dot

Hi, I have a file with below values. /uvxapps/etl/Ascential/DataStage/DSEngine/dsenv.orig /uvxapps/etl/Ascential/DataStage/DSEngine/dsenv /uvxapps/etl/Ascential/DataStage/DSEngine/sample/.cshrc /uvxapps/etl/Ascential/DataStage/DSEngine/sample/.login... (3 Replies)
Discussion started by: njoshi
3 Replies
Login or Register to Ask a Question