Need to replace a . with / which is having a matching Prefix


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to replace a . with / which is having a matching Prefix
# 1  
Old 11-06-2006
Need to replace a . with / which is having a matching Prefix

Hi

Input File:
export NAME='AA.BB.CC'
export FILE=1.2.3
AA.BB.CC
export MAIL= '1.3.3'
export char='XX.YY.ZZ'

Out File
export NAME='AA/BB/CC'
export FILE=1.2.3
AA.BB.CC
export MAIL= '1.3.3'
export char='XX/YY/ZZ'


Only the Lines which have export and have alphabets after = sholuld be searched for . and replaced with /
# 2  
Old 11-06-2006
Code:
sed -e "/export/{s/\./\//g}" input.txt

# 3  
Old 11-06-2006
it is not able to search for 'export' and says a error

Quote:
Originally Posted by vino
Code:
sed -e "/export/{s/\./\//g}" input.txt

sed: 0602-404 Function /export/{s/\./\//g} cannot be parsed.
[tofps8]/home/tofps8/a>
# 4  
Old 11-06-2006
cat inputfile | grep export | sed "s/\./\//g" > out.file
justsam
# 5  
Old 11-06-2006
if we do like that the out put file will have only the line having export

i need the whole file back with the required replacement

Quote:
Originally Posted by justsam
cat inputfile | grep export | sed "s/\./\//g" > out.file
# 6  
Old 11-06-2006
Drop the braces.

Code:
sed -e "/export/s/\./\//g" input.txt

# 7  
Old 11-06-2006
Thats great it works

The sed searches for export first and on those which match it does the replacemnet

Thanks it works great

Quote:
Originally Posted by vino
Drop the braces.

Code:
sed -e "/export/s/\./\//g" input.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace pattern matching

Can anyone help me with sed or awk to do a bulk replace of the below requirements. "REC_ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY ( START WITH +7486 INCREMENT BY +1 MINVALUE +7467 MAXVALUE... (6 Replies)
Discussion started by: ilugopal
6 Replies

2. Shell Programming and Scripting

Extract Uniq prefix from a start and end prefix

Dear All, assume i have a file with content: <Start>6000</Start> <Stop>7599</Stop> the output is: 6000 7000 7100 7200 7300 7400 7599 how should we use any awk, sed, perl can do this task, means to extract the uniq prefixes from the start and stop prefix. Thanks Jimmy (3 Replies)
Discussion started by: jimmy_y
3 Replies

3. Shell Programming and Scripting

sed - Exact pattern matching and replace

Hi Team, I am facing a problem as under, Suppose I have a file (test.txt) with the below content (all braces and slashes are included in the contents of the file) Now I want to append few words below matched line, I have written the below sed: sed '/option/a insert text here' test... (2 Replies)
Discussion started by: ankur328
2 Replies

4. Shell Programming and Scripting

Pattern matching and replace in shell script

Hi I want to find a line in a file which contains a word and replace the patterns. Sample file content temp.xml ==================== <applications> <application> Name="FirstService" location="http://my.website.selected/myfirstService/V1.0/myfirst.war" ... (1 Reply)
Discussion started by: sakthi.99it
1 Replies

5. Shell Programming and Scripting

if characters from positions 7-15 are matching 219 then replace al

Script for if characters from positions 7-15 are matching with characters from position 211-219 then replace all char from 211-219 with 9 space. Total length of record is 420. Here is the specification of the data in file. Position Field Data Type... (2 Replies)
Discussion started by: lancesunny
2 Replies

6. Shell Programming and Scripting

Need help to replace a perl pattern matching

My example file is as given below: conn=1 uid=oracle conn=2 uid=db2 conn=3 uid=oracle conn=4 uid=hash conn=5 uid=skher conn=6 uid=oracle conn=7 uid=mpalkar conn=8 uid=anarke conn=9 uid=oracle conn=1 op=-1 msgId=-1 - fd=104 slot=104 LDAPS connection from 10.10.5.6 to 10.18.6.5 conn=2... (4 Replies)
Discussion started by: sags007_99
4 Replies

7. Shell Programming and Scripting

Replace prefix and suffix of a string

Hi, I'm new about shell scripting, and I need to do something like abcd **1234** efgh by abcd '''1234''' efgh I know that command sed helps about change one string by another, but I dont know how to keep whatever is inside **_** and replace * with '. Thanks! (5 Replies)
Discussion started by: selvaya
5 Replies

8. Shell Programming and Scripting

Longest prefix matching -answer found

Hi Everyone, #!/usr/bin/perl use strict; use warnings; my %prefix_to_rate = ( '93' => "1.50", '6iii' => "0.22" ); my ( $shortest, $longest ) = ( sort { $a <=> $b } map { length } keys %prefix_to_rate ); for my $len ( reverse $shortest .. $longest ) { print ... (0 Replies)
Discussion started by: jimmy_y
0 Replies

9. Shell Programming and Scripting

Replace matching nth occurence

Hi for eg my file has: val1 | val2 | val1 | val2 | val1 | val2 | val1 | val2 | here i need to replace '|' with '|\n' where the occurence of '|' is divisble by 2 so that the output comes like this val1 | val2 | val1 | val2 | val1 | val2 | val1 | val2 | Requesting suggestions in... (1 Reply)
Discussion started by: raghav288
1 Replies

10. UNIX for Dummies Questions & Answers

Pattern Matching - serach and replace script

My requirement is to replace a a particular pattren in a script from A to B. I am not sure if this can be done through sed command or through awk . The file sv.inc is window DialogBox AddConnection tag "~ActiveApp/Add Connection - Provider Type?URL" I would wnat the file to be... (10 Replies)
Discussion started by: bsandeep_80
10 Replies
Login or Register to Ask a Question