[SOLVED] How to use a variable in sed for adding the text into the file?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
it has to be at line 100 not appended to it on the bottom of the file. Other wise if the variable is in the wrong place, being at the end of the file, it will not compile properly nor over write what the variable is set to in the code so it will work with wifi and not eth0.
Quote:
Was there some specific reason you wanted to use sed?
only because it is a tool that is used to replace, and add text into files, and I searched around some more looking to see what awk can do, and found this.
Double quotes, no backslash.
You could use the backslash form if you really wanted, but I wouldn't recommend it in a script. Read the doco more closely for whay.
Double quotes, no backslash.
You could use the backslash form if you really wanted, but I wouldn't recommend it in a script. Read the doco more closely for whay.
are you shure?
Code:
userx@SlackOLatern.net:/media/projects/git-eterm/e16-epplets-0.16/epplets
$ NIC=HoYO
$ sed -i "102i$NIC" net.c
sed: -e expression #1, char 4: expected \ after `a', `c' or `i'
adding the \ again it just
Code:
unsigned char
net_get_bytes_inout(const char *device, double *in_bytes, double *out_bytes)
{
//fix so it will not keep sayig what it is not
device = "wlo1";
$NIC
uses the var name not value, anyways awk does it just fine.
it's Linux, one would then think it is GNU.. hummm, let me look.
Code:
$ sed --version
sed (GNU sed) 4.5
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Jay Fenlason, Tom Lord, Ken Pizzini,
and Paolo Bonzini.
GNU sed home page: <https://www.gnu.org/software/sed/>.
General help using GNU software: <https://www.gnu.org/gethelp/>.
E-mail bug reports to: <bug-sed@gnu.org>.
userx@SlackOLatern.net:/media/projects/git-eterm/e16-epplets-0.16/epplets
$ NIC=HoYO
$ sed -i "102i$NIC" net.c
sed: -e expression #1, char 4: expected \ after `a', `c' or `i'
adding the \ again it just
Code:
unsigned char
net_get_bytes_inout(const char *device, double *in_bytes, double *out_bytes)
{
//fix so it will not keep sayig what it is not
device = "wlo1";
$NIC
uses the var name not value, anyways awk does it just fine.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.