If you want to replace the dot with underscore in all the lines, then use the below sed command:
To restrict for a particular line, then specify a patternCode:sed 's/\./_/g' input.dat
Code:sed '/ONLINE/ s/\./_/g' input.dat
Eg:
word : ONLINE.job
Need like : ONLINE_job
I Know to use 'sed command for file'
sed 's/ / /g' filename ................ but how to do for particular word?
If you want to replace the dot with underscore in all the lines, then use the below sed command:
To restrict for a particular line, then specify a patternCode:sed 's/\./_/g' input.dat
Code:sed '/ONLINE/ s/\./_/g' input.dat
To restrict replacing for a particular word:
Code:sed 's/\(ONLINE\)\.\(job\)/\1_\2/g' input.dat
thanks for your reply anitha....
But ONLINE.JOB is just a example word. I have so many words like this. it will come in iteration way....
Now var i has the word with dot operator..
i = A.b (FIRST TIME)
I=JJJ.B (2ND TIME)
........
.......
LIKE WISE IT IS GOING ON.
So I Need general solution.... like word may be whatever ..... we need to change dot operator to underscore.
The following shell script might work for you:
Use the above code in a while loop for iterations.Code:#!/bin/bash SEARCH_WORD='ONLINE.job' SEARCH_WORD=`echo $SEARCH_WORD|sed 's/\./\\\\./g'` FILENAME='input.dat' REPLACE_WORD=`echo $SEARCH_WORD| sed 's/\./_/'` eval "sed 's/$SEARCH_WORD/$REPLACE_WORD/g' $FILENAME"
Bookmarks