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.
I have a bunch of files that have many columns of space seperated data. I need to search through all those files and find which ones have a specific numerical string - easy to do with the awk command, but awk will list out all those files that have that string in any column or is a part of a larger number. Well that doesn't work for me.
So I'm trying to write an awk script that uses grep that will only search a user specified column of data and must not be part of a larger number. In that second requirement, I'm trying a condition that looks for a space both before and after the numerical string.
I'm thinking this should be fairly simple, and done many times befor, but it's not for me
to loop over a hundred plus files, I can't list them out, so can a do a while/do/done loop like this:
Code:
i=1
numfiles=10000
# choosing a numfiles value that will be much much greater than the actual number of files in the directory
while ((i<=numfiles))
do
awk '$5 == 546 { print FILENAME }' file1 file2 file3 | uniq
((i=i+1))
done
I'm not able to test this right now, maybe not till Friday or Monday, so that's why I'm asking and not testing it out
Could you please remove the long, unbroken "###" lines from your post? They do nothing but make my browser window side-scroll. Thanks.
When posting questions about processing text files, it usually helps to provide an actual example of the input text, and what the output needs to be. Also post any commands you've already tried, so that we can see what you're thinking.
I say this because awk is a full scripting language of its own and capable of doing very exact matches. When you say something like "awk will list out all those files that have that string in any column or is a part of a larger number", that usually just means you haven't used the right awk command.
Is there a way to run this script with a line counter, so that the number of occrances if each line in each file is also listed in the output file. Something like this:
this way now I know not to waste my time on fileDEF.txt and fileIJK.txt and spend more time analying the other files because they have more data for me to use.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.