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/[DialogBox]Add Connection - Provider Type?URL"
I would wnat the file to be displaced as below after it matched the pattern
[+] window DialogBox AddConnection
[ ] tag stAddConnection
If you note the pattern "~ActiveApp/[DialogBox]Add Connection - Provider Type?URL" has been replaced by stAddConnection
Please help
using Perl:
perl -pi -e 's/(tag\s*)(.*)/\1 stAddConnection/' sv.inc
If you want to try out using sed :
sed 's/\(tag\)\(.*\)/\1 stAddConnection/' sv.inc
rgds,
Srini
I have the follwiing piece of code :
for i in `cat valFile`
do
cat tag | while read j
do
echo $j
echo $i
perl -pi -e 's/(j\s*)(.*)/\1 i/' sv.inc > test
done
done
This does not work as i get a balank test file. while the script runs successfully.
Can someone help me please
Hi there,
A Correction. This will work.
for i in `cat valFile`
do
cat tag | while read j
do
echo $j
echo $i
cat sv.inc|perl -pi -e 's/('$j'\s*)(.*)/\1 '$i'/' > test
done
done
Thanks...
I get this error after runinng the script
Substitution pattern not terminated at -e line 1.
Hi Sandeep,
BTW, it works fine for me though. Please see below:
-------------------------------------------------------------------------------
bash-3.00$ cat sample.pl
for i in `cat valFile`
do
cat tag | while read j
do
echo $j
echo $i
cat sv.inc|perl -pi -e 's/('$j'\s*)(.*)/\1 '$i'/' > test
done
done
bash-3.00$ cat valFile
stAddConnection
bash-3.00$ cat tag
tag
bash-3.00$ ./sample.pl
tag
stAddConnection
bash-3.00$ cat test
[+] window DialogBox AddConnection
[ ] tag stAddConnection
bash-3.00$ cat sv.inc
[+] window DialogBox AddConnection
[ ] tag "~ActiveApp/[DialogBox]Add Connection - Provider Type?URL"
bash-3.00$
-------------------------------------------------------------------------------
Perl Gurus,
could you please shed some light on this stated error during execution of a perl script ?
rgds,
Srini
your cat of tag shows
tag
it should be :
cat tag
"~ActiveApp_[DialogBox]Add Connection - Provider Type?URL"
Is this the issue?
Thanks
when i use the sed command also the test file is blank:
cat test2.sh
for i in `cat valFile`
do
cat tag | while read j
do
echo $j
echo $i
sed 's/\('$j'\)\(.*\)/\1 '$i'/' sv.inc > test
done
done
output:
-----------------
"~ActiveApp_[DialogBox]Add Connection - Provider Type?URL"
stAddConnection
sed: -e expression #1, char 30: unterminated `s' command
Hi Sandeep,
I don't think that is the issue. Also, am not too much sure about what the contents of the files, "ValFile" and "tag" are.
According to your initial query, perl will retain the string till "tag" and then removes the entire line afer than and appends "stAddConnection" at the end of the line and thats what the script supplied by me does and as i had indicated previously this stuff works fine for me.
Hope it clarifies.
rgds,
Srini
Yes Srini..Thanks for your help...Let me see if i can fix this myself...