[SOLVED] How to use sed command to dynamically insert line number
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
sed -i "$LINEs/asm/asm-generic/" $FILE #sed not working properly
To be honest, I don't understand the script, but the sed line doesn't work because you use a shell variable named LINEs. Most probably, the intention is
Code:
sed -i "${LINE}s/asm/asm-generic/" $FILE #sed working properly
Last edited by berndbausch; 02-18-2021 at 06:09 AM.
Reason: typo
To be honest, I don't understand the script, but the sed line doesn't work because you use a shell variable named LINEs. Most probably, the intention is
Code:
sed -i "${LINE}s/asm/asm-generic/" $FILE #sed working properly
How to use sed command to dynamically insert line number
Quote:
Originally Posted by sncak
I am trying to dynamically update sed line number using variable
Those are not the same thing, and neither one matches what the code appears to be trying to do.
It's almost always a good idea to provide brief example inputs and outputs, to clarify what you're actually trying to do.
Quote:
Code:
FILE=$(awk 'NR==1{print $1}' log.txt) #getting File path from log file
LINE=$(awk 'END{print}' log.txt) #getting Line number from log file
What does log.txt look like?
Quote:
cat $FILE > comp1
Why not cp "$FILE" comp1 ?
Quote:
sed -i "$LINEs/asm/asm-generic/" $FILE #sed not working properly
Sed is not the problem.
What do you think the LINEs variable contains...?
Also, always wrap filename variables with quotes.
edit: ok, I'm way too slow... how did typing that take 8+ minutes? :'(
And even more importantly, the Linux sources for kernel 5.10.16 still have arch/arm/include/asm and arch/arm/include/uapi/asm. Why are you trying to change this to asm-generic? All you need is to specify the correct include path in the -I flag to compiler.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.