Shell Help with inline sed script

I have come up with a sed script:-
Code:
/umount/a\
\
# Attach the root file system and update /etc/passwd\
echo "**** Attaching UBI file system"\
ubiattach /dev/ubi_ctrl -m 2 -O 2048\
if [ $? != 0 ]; then\
        echo "**** ERROR - Could not attach UBIFS"\
fi\
mdev -s\
mkdir -p /mnt/ubifs\
\
# sleep a while to allow devices to settle\
sleep 5\
\
echo "**** Mounting root file system"\
mount -t ubifs ubi0 /mnt/ubifs\
\
echo "**** Updating system password file"\
sed -i 's/root:\*:/root:\$1\$3h5WisJ4\$JbJ\/AJORbUw8Mf.LtNVtp\/:/' /mnt/ubifs/etc/shadow\

Which I run with sed -f sed.scr

Anyone know how I would use it inline with an <<EOF statement rather than an external script file?
 
I'm fairly certain that sed's -f option can only be pointed to a physical file, not a "here-document" in a shell script.
 
I want something like this in a script:-
Code:
sed 's/world/land/' <<EOF
hello, world
EOF

which can be run using sh script
 
Well, for that you need to use the -e option:
Code:
sed -e 's/that/this/' <<EOF
What's all that here, then?
EOF
 
I wouldn't use sed for general scripting, so I'm not quite sure what you're getting at here. To run your example


sed 's/world/land/' <<EOF
hello, world
EOF


in a sh script, you would start the file with #!/bin/sh and make sure the file is executable:


#!/bin/sh
sed 's/world/land/' <<EOF
hello, world
EOF



~# cat test.sh
#!/bin/sh
sed 's/world/land/' <<EOF
hello, world
EOF
~# chmod u+x ./test.sh
~# ./test.sh
hello, land
 
I wouldn't use sed for general scripting, so I'm not quite sure what you're getting at here.

Please read my original post. I want to insert some into another file, but rather than doing it via an external script I want to insert it inline using the heredoc mechanism.
 
Please read my original post. I want to
Instead of demanding that others read your posts, you should start reading and really learning yourself.
As a high frequency poster you show no progress at all even in the most basic things.

There are thousands of tutorials out there in the Internet. Get one. Work on it. Make your notes. Hack your own keyboard. But stop bothering us that our replies are not sufficient to your needs.

The energy you put in writing posts you better invest in hacking and learning. That worked for most of us here. Start on "learn the learning".

I hope that you might get my "cheap shot" this time.
 
After much trial and error, I managed to come up with something:-
Code:
cat <<EOF >sed.txt
/umount/a\
\\
# Attach the root file system and update /etc/passwd\\
echo "**** Attaching UBI file system"\\
ubiattach /dev/ubi_ctrl -m 2 -O 2048\\
if [ $? != 0 ]; then\\
echo "**** ERROR - Could not attach UBIFS"\\
fi\\
mdev -s\\
mkdir -p /mnt/ubifs\\
\\
# sleep a while to allow devices to settle\\
sleep 5\\
\\
echo "**** Mounting root file system"\\
mount -t ubifs ubi0 /mnt/ubifs\\
\\
echo "**** Updating system password file"\\
sed -i 's/root:\*:/root:\$1\$3h5WisJ4\$JbJ\/AJORbUw8Mf.LtNVtp\/:/' /mnt/ubifs/etc/shadow
EOF

sed -f sed.txt rcS >newrcS
rm sed.txt

I would have preferred to have the whole thing inline without creating an extra file sed.txt but couldn't figure out a way of doing that.
 
Which I run with sed -f sed.scr

Anyone know how I would use it inline with an <<EOF statement rather than an external script file?
As ljboiler already told you, that's not possible. The -f switch expects an actual file whereas a heredoc manipulates stdin.

What's the problem with using the external script file?
 
Back
Top