Skip to main content
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 ...
oliv's user avatar
  • 271
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 ...
J_H's user avatar
  • 42.1k
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,...
Toby Speight's user avatar
  • 88.3k
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. <...
Roland Illig's user avatar
  • 21.9k
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: ...
glenn jackman's user avatar
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. ...
200_success's user avatar
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 ...
tripleee's user avatar
  • 541
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 ...
200_success's user avatar
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. ...
CiaPan's user avatar
  • 1,916
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: ...
chicks's user avatar
  • 2,889
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 ...
oliv's user avatar
  • 271
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 ...
vnp's user avatar
  • 58.7k
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 ...
Kate's user avatar
  • 8,313
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://...
Ed Morton's user avatar
  • 451
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. ...
Bruno's user avatar
  • 131
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 ...
Sara J's user avatar
  • 4,221
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 ...
janos's user avatar
  • 113k
3 votes

Shell script to count chess game outcomes

TL;DR ...
Gao's user avatar
  • 1,230
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. ...
glenn jackman's user avatar
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 ...
janos's user avatar
  • 113k
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 ...
AJNeufeld's user avatar
  • 35.3k
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 ...
Ed Morton's user avatar
  • 451
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 ...
jas-'s user avatar
  • 262
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: ...
Oh My Goodness's user avatar
2 votes
Accepted

Extract sections of a file into separate files

Try to close your filename only when it's necessary: File actg.awk ...
Arnaud Valmary's user avatar
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 ...
Toby Speight's user avatar
  • 88.3k
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. ...
janos's user avatar
  • 113k
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 ...
Ed Morton's user avatar
  • 451
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: ...
Toby Speight's user avatar
  • 88.3k
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 ...
Arlion's user avatar
  • 238

Only top scored, non community-wiki answers of a minimum length are eligible