sed command to replace slash in date format only


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed command to replace slash in date format only
# 1  
Old 09-11-2013
sed command to replace slash in date format only

Hello experts.

I haven't been able to find a solution for this using the sed command.

I only want to replace the forward slash with string "FW_SLASH" only if there's a number right after the slash while preserving the original number.

I have a file containing 2 entries:
Code:
Original File:
/data/usr/one.txt
/01/02/2001

Code:
Desired File:
/data/usr/one.txt
FW_SLASH01FW_SLASH02FW_SLASH2001

I have tried this code but I'm not able to preserve the original number:
Code:
sed 's/\/[0-9]/FWD_SLASH/g'

Thanks.
# 2  
Old 09-11-2013
Code:
sed 's|/\([0-9][0-9]*\)|FW_SLASH\1|g' infile

This User Gave Thanks to verdepollo For This Post:
# 3  
Old 09-11-2013
Or more short:
Code:
sed 's/\//FWD_SLASH/g' infile

Regards.
# 4  
Old 09-11-2013
Quote:
Originally Posted by disedorgue
Or more short:
Code:
sed 's/\//FWD_SLASH/g' infile

Regards.
That would substitute the no-digit line, too.
# 5  
Old 09-12-2013
It's true, I'm attached specific case and not general Smilie
but, in this case:
Code:
sed 's|/\([0-9]\+\)|FW_SLASH\1|g' infile

work as verdepollo version, but both not work with example /0FOO/2BAR/2001

Regards.
# 6  
Old 09-12-2013
Some sed versions support word-boundary anchors \< and \>
Code:
$ echo /0FOO/2BAR/2001 | sed 's|/\([0-9][0-9]*\)|FW_SLASH\1|g'
FW_SLASH0FOOFW_SLASH2BARFW_SLASH2001
$ echo /0FOO/2BAR/2001 | sed 's|/\([0-9][0-9]*\>\)|FW_SLASH\1|g'
/0FOO/2BARFW_SLASH2001

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sed/awk command to convert number occurances into date format and club a set of lines

Hi, I have been stuck in this requirement where my file contains the below format. 20150812170500846959990854-25383-8.0.0 "ABC Report" hp96880 "4952" 20150812170501846959990854-25383-8.0.0 End of run 20150812060132846959990854-20495-8.0.0 "XYZ Report" vg76452 "1006962188"... (6 Replies)
Discussion started by: Chinmaya Kabi
6 Replies

2. Shell Programming and Scripting

Display date in mm/dd/yy format in sed command

Hi All, Following is my issue. $MAIL_DOC = test.txt test.txt contains the following text . This process was executed in the %INSTANCE% instance on %RUNDATE%. I am trying to execute the following script var=`echo $ORACLE_SID | tr ` NOW=$(date +"%D") sed -e... (3 Replies)
Discussion started by: megha2525
3 Replies

3. Shell Programming and Scripting

to replace Date format issue

Hi, I have the below data in a file in one of the path, 101 02100002111406893401207310900A094101xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 5200xxxxxxxxxx D18000_1 CCDXXXXXXX JUL 31201207 1140689340000001 622113010547999999999003 000333333334RE ... (1 Reply)
Discussion started by: Ramyajiguru1
1 Replies

4. Shell Programming and Scripting

Using sed command replace date variable in unix

I need to use a shell script, using sed command how to replace date variable value in following format. 04/18/2012 11:38:55 Because the sed is treating the '/' as a parameter instead of the value of a variable, and hence there is the message as sed: command garbled: s/insert/04/18/2012... (9 Replies)
Discussion started by: jannusuresh
9 Replies

5. Shell Programming and Scripting

AWK or SED to replace forward slash

hi hope somebody can help, there seems to be bit on the net about this, but still cant make it work the way i need. i have a file live this mm dd ff /dev/name1 mm dd ff /dev/name2 mm dd ff /dev/name3 mm dd ff /dev/name4 i need to update /dev/name1 etc to /newdev/new/name1 etc so... (5 Replies)
Discussion started by: dshakey
5 Replies

6. UNIX for Dummies Questions & Answers

Replace Forward Slash with sed

i need to replace '/' forward slash with \/(backward slash follwed by a forward slash) using sed command when the forward slash occurs as a first character in a file.. Tried something like this but doesn't seem to work. find $1 -print0 | xargs -0 sed -i -e 's/^\//\\\//g' Can someone... (19 Replies)
Discussion started by: depakjan
19 Replies

7. Shell Programming and Scripting

Format of SED command to change a date

I have a website. I have a directory within it with over a hundred .html files. I need to change a date within every file. I don't have an easy way to find/replace. I need to change 10/31 to 11/30 on every single page at once. I tried the command below but it didn't work. Obviously I don't know... (3 Replies)
Discussion started by: ijustsawmars
3 Replies

8. Shell Programming and Scripting

How to replace comma by slash using sed in an UTF8 file

Hello all, I'd like to replace "," by "/" in a utf8 file from postion X to Y. Comma "," is also defined as delimiter. 12345678901234567890,123456789012345,12345678901234567890, aaaa,aaaa,aaaaa ,bbb,bbbb,bbbbb ,cccccc,cc , Result should be... (1 Reply)
Discussion started by: fmofmo
1 Replies

9. Shell Programming and Scripting

Using sed to append backward slash before forward slash

Hi all, I need to know way of inserting backward slash before forward slash. My problem is that i need to supply directory path as an argument while invoking cshell script. This argument is further used in script (i.e. sed is used to insert this path in some file). So i need to place \ in front... (2 Replies)
Discussion started by: sarbjit
2 Replies

10. Shell Programming and Scripting

How to parse slash / in sed command..

Hi All, I am trying to replace paths with \ (as in NT) with / (as in Unix) in a script using sed. Following is the command I use: sed "s/e:\Kenny_test\csv_files/var/opt/ciw/data/outbound/g" EMEA4710.SQL > test the string to replace is e:\Kenny_test\csv_files the target string needs to... (3 Replies)
Discussion started by: Abhidey
3 Replies
Login or Register to Ask a Question