Efficient File Manipulation and Selection with Awk Command: Step-by-Step Guide

  • Thread starter Thread starter confi999
  • Start date Start date
AI Thread Summary
To efficiently manage a large number of files, the discussion focuses on using the awk command for file manipulation. The user seeks to delete files named from 'file003001.txt' to 'file008000.txt' and extract specific data from the remaining files. However, forum participants suggest that using shell commands like `rm` for deletion and simple shell globbing for file selection is more effective than awk for these tasks. They recommend using shell commands for filtering files based on their names, while awk can be reserved for processing the data within the selected files. Overall, the conversation emphasizes leveraging the strengths of both shell commands and awk for efficient file handling.
confi999
Messages
18
Reaction score
0
Hello,
I have about 8000 files in a directory all having names like
file000001.txt
file000002.txt
file000003.txt
file000004.txt
----------
----------
file007999.txt
file008000.txt

Now I need to do 2 things:

1. I found out that I don't actually need the data from the files whose names are above 'file003000.txt'. So I want to delete the 5000 files from 'file003001.txt' through 'file008000.txt' using awk. (I don't know how to do this part) I will then take the values of column 3 of each of the remaining files if column 1 == 20 and put these in 'select.txt' file (I know how to do this part).

2. I believe it is possible (but I am not being able to do it) even without deleting those 5000 files to write an awk command that will only take files which has values less than / equal to 'file003000.txt' and do the latter part on them i.e. taking the values of column 3 of each file if column 1 == 20 and put these in 'select.txt' file. In other words it is something like if VARIABLE<=3000 in 'file00VARIABLE.txt' consider it otherwise ignore it.

How can I do both of the above using awk (one liner preferred than scripts).
Any help is highly appreciated. Thank you.
 
Technology news on Phys.org
confi999 said:
1. I found out that I don't actually need the data from the files whose names are above 'file003000.txt'. So I want to delete the 5000 files from 'file003001.txt' through 'file008000.txt' using awk. (I don't know how to do this part)
Why use awk? Just use the command line. In csh/tcsh,
rm file00[3-8]?.txt

2. I believe it is possible (but I am not being able to do it) even without deleting those 5000 files to write an awk command that will only take files which has values less than / equal to 'file003000.txt'
Don't use awk to do the filtering that is easier done at the shell level.
awk -f script.awk file00[0-2]?.txt
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Back
Top