f



Sed substitution on v7r1 not working

Hi,

iSeries is not my platform however this is still a basic question that has =
most of us stumped.

Create a file called Test.txt and add the following lines to the text file=
=20

   /QIBM/TP                   =20
   /QIBM/TPP                  =20
   /QIBM/No                 =20

Then run sed command:

> sed 's/TP/xx/g' test.txt   =20
   /QIBM/xx                   =20
   /QIBM/xxP                  =20
   /QIBM/No=C2=A3                  =20


Then check the file but it hasn't changed!

 > cat test.txt               =20
   /QIBM/TP                   =20
   /QIBM/TPP                  =20
   /QIBM/No=C2=A3                  =20

So it echoes (because there is no -n switch applied) but it never actually =
updates the file. File permissions are fine as I can edit the file using ed=
tf.

I appear to be missing the equivalent -i switch from UNIX (edit files in pl=
ace (makes backup if extension supplied)but from the information center the=
re is no equivalent.=20

So, what am I missing?

Much appreciated.

EddieTurbo
0
EddieTurbo
10/18/2016 6:02:09 PM
comp.sys.ibm.as400.misc 9219 articles. 3 followers. Post Follow

3 Replies
278 Views

Similar Articles

[PageSpeed] 49

On Tuesday, 18 October 2016 19:02:11 UTC+1, EddieTurbo  wrote:
> Hi,
>=20
> iSeries is not my platform however this is still a basic question that ha=
s most of us stumped.
>=20
> Create a file called Test.txt and add the following lines to the text fil=
e=20
>=20
>    /QIBM/TP                   =20
>    /QIBM/TPP                  =20
>    /QIBM/No                 =20
>=20
> Then run sed command:
>=20
> > sed 's/TP/xx/g' test.txt   =20
>    /QIBM/xx                   =20
>    /QIBM/xxP                  =20
>    /QIBM/No=C2=A3                  =20
>=20
>=20
> Then check the file but it hasn't changed!
>=20
>  > cat test.txt               =20
>    /QIBM/TP                   =20
>    /QIBM/TPP                  =20
>    /QIBM/No=C2=A3                  =20
>=20
> So it echoes (because there is no -n switch applied) but it never actuall=
y updates the file. File permissions are fine as I can edit the file using =
edtf.
>=20
> I appear to be missing the equivalent -i switch from UNIX (edit files in =
place (makes backup if extension supplied)but from the information center t=
here is no equivalent.=20
>=20
> So, what am I missing?
>=20
> Much appreciated.
>=20
> EddieTurbo

You are missing the i switch. Its not shown in the manual and qsh complains=
 if you add it. At least not at V7.1 with the ptfs I have loaded.

Redirect your output then delete & rename:
sed 's/TP/xx/g' test.txt > test.tmp
rm test.txt
mv test.tmp test.txt   =20

Your pound sign had me confused for a moment, coming right after 'No'. (Mig=
ht be a hash or dollar originally)

Jonathan
0
Jonathan
10/20/2016 1:17:41 PM
On Thursday, October 20, 2016 at 2:17:48 PM UTC+1, Jonathan Bailey wrote:
> On Tuesday, 18 October 2016 19:02:11 UTC+1, EddieTurbo  wrote:
> > Hi,
> >=20
> > iSeries is not my platform however this is still a basic question that =
has most of us stumped.
> >=20
> > Create a file called Test.txt and add the following lines to the text f=
ile=20
> >=20
> >    /QIBM/TP                   =20
> >    /QIBM/TPP                  =20
> >    /QIBM/No                 =20
> >=20
> > Then run sed command:
> >=20
> > > sed 's/TP/xx/g' test.txt   =20
> >    /QIBM/xx                   =20
> >    /QIBM/xxP                  =20
> >    /QIBM/No=C2=A3                  =20
> >=20
> >=20
> > Then check the file but it hasn't changed!
> >=20
> >  > cat test.txt               =20
> >    /QIBM/TP                   =20
> >    /QIBM/TPP                  =20
> >    /QIBM/No=C2=A3                  =20
> >=20
> > So it echoes (because there is no -n switch applied) but it never actua=
lly updates the file. File permissions are fine as I can edit the file usin=
g edtf.
> >=20
> > I appear to be missing the equivalent -i switch from UNIX (edit files i=
n place (makes backup if extension supplied)but from the information center=
 there is no equivalent.=20
> >=20
> > So, what am I missing?
> >=20
> > Much appreciated.
> >=20
> > EddieTurbo
>=20
> You are missing the i switch. Its not shown in the manual and qsh complai=
ns if you add it. At least not at V7.1 with the ptfs I have loaded.
>=20
> Redirect your output then delete & rename:
> sed 's/TP/xx/g' test.txt > test.tmp
> rm test.txt
> mv test.tmp test.txt   =20
>=20
> Your pound sign had me confused for a moment, coming right after 'No'. (M=
ight be a hash or dollar originally)
>=20
> Jonathan



Thanks for that Jonathan.

The pound sign was reported when the command ran. Not too worried about tha=
t right now.

Basically I didn't want to to kill the discussion with complexity before I =
got to this point.=20

The change is recursive ..... so +10,000 files so is there an easy way to h=
andle this next layer?=20

With it '-i' switch in Unix-land it replaces within the file. If I have to =
redirect and then rename it may well be too difficult on iSeries .... what'=
s your thoughts.

Thanks,

Eddie
0
EddieTurbo
10/25/2016 7:12:15 PM
On Tuesday, 25 October 2016 20:12:17 UTC+1, EddieTurbo  wrote:
> On Thursday, October 20, 2016 at 2:17:48 PM UTC+1, Jonathan Bailey wrote:
> > On Tuesday, 18 October 2016 19:02:11 UTC+1, EddieTurbo  wrote:
> > > Hi,
> > >=20
> > > iSeries is not my platform however this is still a basic question tha=
t has most of us stumped.
> > >=20
> > > Create a file called Test.txt and add the following lines to the text=
 file=20
> > >=20
> > >    /QIBM/TP                   =20
> > >    /QIBM/TPP                  =20
> > >    /QIBM/No                 =20
> > >=20
> > > Then run sed command:
> > >=20
> > > > sed 's/TP/xx/g' test.txt   =20
> > >    /QIBM/xx                   =20
> > >    /QIBM/xxP                  =20
> > >    /QIBM/No=C2=A3                  =20
> > >=20
> > >=20
> > > Then check the file but it hasn't changed!
> > >=20
> > >  > cat test.txt               =20
> > >    /QIBM/TP                   =20
> > >    /QIBM/TPP                  =20
> > >    /QIBM/No=C2=A3                  =20
> > >=20
> > > So it echoes (because there is no -n switch applied) but it never act=
ually updates the file. File permissions are fine as I can edit the file us=
ing edtf.
> > >=20
> > > I appear to be missing the equivalent -i switch from UNIX (edit files=
 in place (makes backup if extension supplied)but from the information cent=
er there is no equivalent.=20
> > >=20
> > > So, what am I missing?
> > >=20
> > > Much appreciated.
> > >=20
> > > EddieTurbo
> >=20
> > You are missing the i switch. Its not shown in the manual and qsh compl=
ains if you add it. At least not at V7.1 with the ptfs I have loaded.
> >=20
> > Redirect your output then delete & rename:
> > sed 's/TP/xx/g' test.txt > test.tmp
> > rm test.txt
> > mv test.tmp test.txt   =20
> >=20
> > Your pound sign had me confused for a moment, coming right after 'No'. =
(Might be a hash or dollar originally)
> >=20
> > Jonathan
>=20
>=20
>=20
> Thanks for that Jonathan.
>=20
> The pound sign was reported when the command ran. Not too worried about t=
hat right now.
>=20
> Basically I didn't want to to kill the discussion with complexity before =
I got to this point.=20
>=20
> The change is recursive ..... so +10,000 files so is there an easy way to=
 handle this next layer?=20
>=20
> With it '-i' switch in Unix-land it replaces within the file. If I have t=
o redirect and then rename it may well be too difficult on iSeries .... wha=
t's your thoughts.
>=20
> Thanks,
>=20
> Eddie

The following script works OK for me:
Filename ss.sh
  test -f $1.txt
  if [[ $? !=3D 0 ]]; then return 1; fi
  sed $2 $1.txt > $1.tmp
  rm $1.txt
  mv $1.tmp $1.txt

then execute
chmod +x ss.sh
& run=20

ss.sh xxx 's/TP/xx/g'=20
-gives nothing
ss.sh test 's/TP/xx/g'=20
-gives a new file called test.txt with the expected replacements, provided =
ss.sh is in your path.

so replacing sed with ss.sh works for this replacement.
If all your files don't end with .txt, remove all the .txt from the script =
and=20
ss.sh test.txt 's/TP/xx/g'=20
You would also be better with a check on $# to make sure 2 parameters are p=
assed to the script.
If you already have a massive script you can 'just' embed the sed function =
with
sed (){
....
}
and then sed is overridden in this script (I hope).

The 'normal' issues with shell special chars obviously have their added int=
erest, & some peculiarities just for ibm I too. I find the [] don't always =
work & I have to use ^] but its been OK today. Maybe I didn't try since I u=
pgraded from 5.4 to 7.1 & also ptfs could play a part.

Jonathan
0
Jonathan
10/26/2016 1:20:30 PM
Reply: