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.
no is not the fhirs line
i want to delet the line where is finding the string which i give it no mather cuz is fhirs second third fourt or anywhere else i want to delete the entire line where is finding the given string
i want to when i grep <1> to print what is after the " = " but i cant do it because my grep print even if he find <1> after the " ="
so i want to search the lines befor the " = " and print what is after " = "
i dont know if you understand but i realy need help
Last edited by sparky90ful; 09-28-2013 at 04:05 AM.
the problem with using grep is you need to write a temporary file and then move it to your target file
sometimes it is convenient to do it this way, for instance when working on the command line, trying a few things out.
But for scripts, it is not the correct tool.
the thing is for example i want to serch 1 so i want cuz he find me the lines where is 1 but before " = " so i dont wnt cuz he find <a=1> or <ddd=321> i wat to find <1=ghfh> or <211=op14> or <421=kj5417> and when he find this print what is after " = " so the result will be " ghf " " op14 " " kj5417 " and that is i hope now is god explained
Last edited by sparky90ful; 09-28-2013 at 04:20 AM.
but now i am stuck in another thing i want to dysplay the value where exist my result of grep for example i have this:
Code:
g=7
h=8
i=9
j=10
k=11
i want to when i grep <1> to print what is after the " = " but i cant do it because my grep print even if he find <1> after the " ="
so i want to search the lines befor the " = " and print what is after " = "
i dont know if you understand but i realy need help
I'm going to introduce you to awk
like sed you can have 'awk one liners' , do a web search
awk is very powerful
but here we shall use the basics
Code:
awk -F= '$1 == "g" {print $2}' sh.db
can make it easier to read/understand
Code:
awk -F= '{ if ( $1 == "g" ) {print $2} }' sh.db
-F< field separator >
$1 $2 .... are the fields, don't get them confused with shell script variables
like sed you can have 'awk one liners' , do a web search
awk is very powerful
but here we shall use the basics
Code:
awk -F= '$1 == "g" {print $2}' sh.db
can make it easier to read/understand
Code:
awk -F= '{ if ( $1 == "g" ) {print $2} }' sh.db
-F< field separator >
$1 $2 .... are the fields, don't get them confused with shell script variables
i can't understand this.......soo awk=search -F=field separator so i tell him to search a field separator and do wat "g" i replace g with what i search befor field separator??? for my example yo do how with awk?
Code:
the thing is for example i want to serch 1 so i want cuz he find me the lines where is 1 but before " = " so
i dont wnt cuz he find <a=1> or <ddd=321>
i wat to find <1=ghfh> or <211=op14> or <421=kj5417> and when he find this print what is after " = "
so the result will be " ghf " " op14 " " kj5417 " and that is i hope now is god explained
Last edited by sparky90ful; 09-28-2013 at 04:36 AM.
i think i get it i test it and i come back with a replay
now i see but the thing is i want to give me not only "bar" but even "barfoo" so foo must be the right word searched or foobar or coolfooten or any who contain tis foo i want what is after =
Last edited by sparky90ful; 09-28-2013 at 04:58 AM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.