Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I find and change.....

Status
Not open for further replies.

jarod

Programmer
Aug 10, 2001
6
US
Hi,
could please help me to find and change specific char.

My file is like that:

:12:xxx vvv ggg
:13:ggggggg zzzzzz
:35B:aaaaa bbbbbbbb
ccccc:dddddd
:33B:ttttt zzzzzzz

How can I find the char : between ccccc and dddddd and change it to a /

Thanks for your help
Jarod
 

Hi, jarod!

If I properly understood your problem, maybe you can match entire row of pattern /ccccc:dddddd/ and print "ccccc/dddddd" instead old row:

Code:
awk '/ccccc:dddddd/ { print "ccccc\/dddddd"; next }  { print }' inputfile

Bye!

KP.

 
Hi KP,
First of all thanks for your quick answer.

The problem is that in the file there are more than one line wich start with :35B: and I don't know what I can find before and after the char :

So the change must consider all line wich start with :35B:

Thanks
Jarod
 

Hi again, Jarod!

You can also use sed for this kind of problems:

Code:
sed -e 's/:35B:/\/35B\//g' file.txt

God bless you! Bye!

KP.
 
Salut KP,

I don't want to change :35B: but only the next : wich found between 2 string.

Thanks,
Jarod
 
If I quite understood your problem, maybe this gawk solution helps you:

Code:
C:\TEMP\awk>awk -F: '{ if (sw) { gsub(/:/,"\/"); print; sw = 0; next }}
$2 ==  "35B" { sw = 1 }  { print }' inputfile

This gawk program changes line after line with pattern '35B'.

Bye!

KP.
 

Oops,

Previos gawk program changes line after line which the 2nd field has value '35B'.

Bye again!

KP.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top