Replace a format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replace a format
# 1  
Old 05-10-2011
Replace a format

I have a file which contains
Code:
1.3.6.1.4.1.637.61.1.35.10.19.1.10
1.3.6.1.4.1.637.61.1.35.15.3.1.4

Now i want to replace the last occurance of ".1." to ":"
The output should look like
Code:
1.3.6.1.4.1.637.61.1.35.10.19:10
1.3.6.1.4.1.637.61.1.35.15.3:4


Last edited by joeyg; 05-10-2011 at 02:16 PM.. Reason: Please use CodeTags around commands and data
# 2  
Old 05-10-2011
Code:
echo '1.3.6.1.4.1.637.61.1.35.10.19.1.10' | sed 's/\(.*\)\.\(.*\)/\1:\2/'
echo '1.3.6.1.4.1.637.61.1.35.10.19.1.10' | sed 's/\.\([^.]*\)$/:\1/'


Last edited by vgersh99; 05-10-2011 at 02:29 PM..
# 3  
Old 05-10-2011
Try:
Code:
perl -pe 's/\.1\.(\d+)$/:\1/' file

# 4  
Old 05-10-2011
Quote:
Originally Posted by vgersh99
Code:
echo '1.3.6.1.4.1.637.61.1.35.10.19.1.10' | sed 's/\(.*\)\.\(.*\)/\1:\2/'
echo '1.3.6.1.4.1.637.61.1.35.10.19.1.10' | sed 's/\.\([^.]*\)$/:\1/'

@vgersh99,

You are replacing the last dot but the OP needs to replace the last occurance of ".1." with a ":".


Another one:
Code:
sed 's/\(.*\)\.1\.\(.*\)/\1:\2/' file

This User Gave Thanks to Franklin52 For This Post:
# 5  
Old 05-10-2011
Quote:
Originally Posted by Franklin52
@vgersh99,

You are replacing the last dot but the OP needs to replace the last occurance of ".1." with a ":".
You're right - I misread the requirement.
Thanks.
# 6  
Old 05-10-2011
Thanks all and Thanks Franklin52... It worked... Smilie
# 7  
Old 05-10-2011
Was just curious to create one with awk

Code:
awk -F"[.]1[.]" '{$NF=":"$NF;gsub(/ /,".1.");sub(".1.:",":")}1' infile

regards,
Ahamed
This User Gave Thanks to ahamed101 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read from file and replace in format

Hi Guys, I am having below content in a file which is tab dimited file.txt AUS AUS_UP NZ NZ_UP ENG ENG_AP I need to read the file content and replace it with below output format one to one replace try("AUS ").ss("AUS_UP") try("NZ ").ss("NZ_UP") try("ENG ").ss("ENG_AP") (3 Replies)
Discussion started by: rohit_shinez
3 Replies

2. Shell Programming and Scripting

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: Original File:... (5 Replies)
Discussion started by: pchang
5 Replies

3. Shell Programming and Scripting

How can I replace data in between xml tags to required format?

Hi All, I have a requirement to change the data in xml file to required format. Below is the scenario. Please find the attached Xml file which contains data that I need to convert.. <ReleaseIndicatorList><ReleaseIndicator>Alternative... (0 Replies)
Discussion started by: Prathyu
0 Replies

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

5. Shell Programming and Scripting

perl module to convert xlsx format to xls format

Hi Folks, I have written a perl script that reads data from excel sheet(.xls) using Spreadsheet::ParseExcel module. But the problem is this module doesn't work for excel sheets with extension .xlsx. I have gone through Spreadsheet::XLSX module with which we can read from .xlsx file directly.... (1 Reply)
Discussion started by: giridhar276
1 Replies

6. Shell Programming and Scripting

PERL : hhmiss - Date format check and replace

I have a filename, This can be any of any format, I want to check if the filename has hours,mins and seconds part. If it is present, i want to replace it with a " * " (star symbol) output needed: IMP: The time part can be in any pattern. How can this be done?:confused:... (3 Replies)
Discussion started by: irudayaraj
3 Replies

7. Shell Programming and Scripting

Date format check and replace string in PERL

I have got few date format patterns like "yyyymmdd", "yy_mm_dd" etc. There can be any combination of such patterns. I have used add_delta_days to find "yyyy", "yy", "mm", "dd" for the current date and saved them to different variables like "$y1", "$y2", "$m1" etc In one line, i want to... (10 Replies)
Discussion started by: irudayaraj
10 Replies

8. Shell Programming and Scripting

Help with sed matching <tag1> newline spaces <tag2> and replace the value in the same string format

Hi, I'm very new to shell scripting and have searched google and this forum for quite some time now. I have the following in my xml file: <recipients> <member>value1</member> </recipients> I need to find a string <recipients> that follows with a new-line and bunch of spaces and... (5 Replies)
Discussion started by: mgharios
5 Replies

9. Shell Programming and Scripting

How to search a date format from a file an replace with a string in PERL

I am very new to Perl. I am struggling so hard to search a date (such as 10/09/2009, 10-09-2009) from a text file and replace with a string (say DATE) using Perl. Please help me out. Thanks in advance. Regds Doren (4 Replies)
Discussion started by: my_Perl
4 Replies

10. Shell Programming and Scripting

replace time format

Hello All, I have a problem with the following text file. For the field number 5 which is the time format (hh:mm:ss). But I would like to delete "ss" and showing hh:mm only. 00001,CLIENT,Company,1218,N,1:04,35,0.211,0,0.211,1.155531,0:00,0,0,0,0,0,1:04,35,0.211,0,0.211,1.155531,foold... (16 Replies)
Discussion started by: happyv
16 Replies
Login or Register to Ask a Question