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.
In awk , we choose which field to return by variables $1,$2 ,......
this will list the fields wanted for all records (where record is a single line of the returned values), the returned values may have more that 1 record usually.
I need to select a single record , mean to get the output of the awk result line by line.
how can this be doen ,
( I need this for many things , ex: deleting all directories with name ".sss" (by filtering the find results through awk then pass record-by-record to rm) , and may others usages.
Thanks for your replay ,, let me give an example please:
Code:
find ./ -name ".svn"
will give:
./docroot/editor/skins/silver/toolbar/.svn
./docroot/editor/filemanager/.svn
./docroot/editor/filemanager/browser/.svn
./docroot/editor/filemanager/browser/default/images/.svn
./docroot/editor/filemanager/browser/default/images/icons/.svn
..... 100 more lines
I wonder how to delete them ? i have thought in awk , I want awk to return one line (RECORD) at a time so i can delete them through redirecting (awk or other) output to rm.
also:
Code:
ps aux | awk '/httpd/ {print $2}'
will give
1111
2222
3333
as process IDs
and I need to kill them all, so I need to get the values line-by-line or in awk terms: as records.
find ./ -name ".svn"
will give:
./docroot/editor/skins/silver/toolbar/.svn
./docroot/editor/filemanager/.svn
./docroot/editor/filemanager/browser/.svn
./docroot/editor/filemanager/browser/default/images/.svn
./docroot/editor/filemanager/browser/default/images/icons/.svn
..... 100 more lines
I wonder how to delete them ? i have thought in awk , I want awk to return one line (RECORD) at a time so i can delete them through redirecting (awk or other) output to rm.
The 2 easiest ways are:
Use the -exec option that comes with find. I.e: find ./ -name ".svn" -exec rm {} \;
If you want to know, beforehand, what will be deleted change rm to ls.
Another way is:
find ./ -name ".svn" | xargs rm
The find command, in both examples, will return what you are looking for and gives this to (example one) rm by using the -exec parameter, or pipes it to xargs rm in the second example.
Quote:
also:
Code:
ps aux | awk '/httpd/ {print $2}'
will give
1111
2222
3333
as process IDs
and I need to kill them all, so I need to get the values line-by-line or in awk terms: as records.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.