9
votes
Print code-fenced sections of a Markdown document
While your code looks ok, it could be improved greatly by making use of RS (record separator) and NR number of record, provided ...
9
votes
Accepted
Generate filesystem usage report using Awk
ISO dates
Yeah, I get it that you have a pre-defined data format.
Input Data Format
Month (in MM.YYYY format)
But that's significantly less than ideal.
If feasible, try to get new records produced ...
7
votes
Count unique IP address in a date range from Apache log
I assume there's a simply copy-paste error where you have | at the start of a line, instead of at the end of the preceding line?
If we're just going to count lines,...
7
votes
Print code-fenced sections of a Markdown document
The Code looks perfect to me.
I thought about using the flip-flop operator, but since you take additional action at the beginning and the end of the code block, this may be difficult in this case.
<...
6
votes
Accepted
Remove every line that include and follows the second occurrence of a given pattern
This should be pretty speedy:
awk '/bar/ {n++} n==2 {exit} {print}' file
To pass the pattern from the shell:
...
6
votes
Code to get the IP address and format it to run in nmap
You can do it purely in Bash, using ${parameter%word} to strip off the last octet from the IP address.
...
5
votes
Accepted
Count unique IP address in a date range from Apache log
Here's a refactoring which condenses much of the logic after the zgrep into a single Awk script.
Prefer modern ...
5
votes
Accepted
Select second field in text table with shell script
Your idea to transform the table so that the implied keys explicitly appear on every row is an interesting one, but I think that it is overcomplicated.
The backslashes to indicate continuation lines ...
4
votes
Accepted
Print code-fenced sections of a Markdown document
You could shorten the code with the next statement, which skips the current rule as well as all following it and starts a next iteration on the next input record.
...
4
votes
Accepted
Code to get the IP address and format it to run in nmap
This is pretty reasonable. I'd have awk do a bit more of the work:
...
4
votes
Parsing GTF file using command-line
Your code can be simplified with only awk script:
awk '/exon/ {gsub("[\";]","", $10);print $1,$4,$5,$7,$10}' file.gtk
...
4
votes
Processing a very long single line of comma-separated (?) floating point numbers
awk is a very powerful programming language. If you plan to invoke it, you likely need neither grep nor ...
4
votes
Generate filesystem usage report using Awk
Ah good old awk. I believe this program is 50 years old!
Your script is a good illustration of what can be achieved with this tool. But as hinted already, it may not be the best tool for the job.
If I ...
4
votes
Accepted
Script to format Markdown as plain text
You never need sed when you're using awk. Pipes of sed-or-grep-or-awk to sed-or-grep-or-awk are an antipattern (see https://...
3
votes
Compare script using awk and bash
Well, it took time to figure out what your program is doing. So I did shorten it in two phases.
First phase: I removed all duplicate temporary files, and used a pipe when a temp file was used once.
...
3
votes
Accepted
Parse log file and send the result to an API
As @TobySpeight pointed out in a comment, the cat is redundant. Any time you have a line like ...
3
votes
Count unique IP address in a date range from Apache log
Drop the unnecessary time part
The time part of the date doesn't play a role in the filtering.
You could drop it and the script will be simpler.
Use more variables
I find this line a bit difficult ...
3
votes
3
votes
Accepted
Counts and average code
This is not very much different from your solution. It does not rely on the header being hardcoded though. Depends on GNU awk for the use of PROCINFO to control array traversal.
...
3
votes
Updating my package version using only a Makefile
I think there's an easier way to get this done:
Extract the semver part from the tag (as you already did)
Use conditionals to determine the field to increment
Use a single Awk to increment the ...
3
votes
Accepted
Awk program for extracting unique values from a k1=v1,k2=v2,... list
The array values are irrelevant. Instead of
vals[arr[2]] = arr[2]
you could use
vals[arr[2]] = 1
to indicate ...
3
votes
Generate filesystem usage report using Awk
There's too much code to look through all of it, but to answer your specific comments:
Would you put all of the logic into the Awk program, or leave some of the validation in the shell driver?
A ...
2
votes
Accepted
Bash script for managing hashtag notes
The use of $(CMD) vs `CMD` is the right way to reassign command output to variables.
The overall flow looks sound, not a ton of ...
2
votes
Accepted
Removing duplicate field entries from sorted csv data
The shell is usually a poor choice for processing data. Let awk do it for you:
...
2
votes
Accepted
Extract sections of a file into separate files
Try to close your filename only when it's necessary:
File actg.awk
...
2
votes
Printing of status message during execution of the bash script
I see very little error-checking in this script. It's important to know whether mkdir succeeded, for example (it certainly won't as it stands, as ...
2
votes
Split Text to Columns and move all data to the next column
Consider using Python
This relatively simple task is not trivial to implement in Bash.
It would be straightforward in Python,
present in modern systems,
and I think it would be worth the investment.
...
2
votes
awk script to pivot long CSV into wide CSV
When I say "GNU-ism" below about any specific construct I really mean "non-POSIX but will work in GNU awk and MAY work in some other awks".
To read CSV in general with awk see ...
2
votes
Generate filesystem usage report using Awk
Other reviews have made most of the points I would raise. There's another issue lurking here:
...
1
vote
Accepted
Bash script wallpaper randomizer
Why you shouldn't parse ls.
Let's consider ls bad practice, and allow me to introduce a different method to solve your issue all together. Find every file in the ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
awk × 57bash × 36
linux × 12
sed × 12
shell × 7
regex × 5
csv × 5
python × 3
performance × 3
parsing × 3
console × 3
python-3.x × 2
strings × 2
bioinformatics × 2
unix × 2
beginner × 1
php × 1
sql × 1
time-limit-exceeded × 1
datetime × 1
reinventing-the-wheel × 1
comparative-review × 1
validation × 1
file-system × 1
homework × 1