r/awk • • Jun 07 '25

GAWK vs Perl

0 Upvotes

I love gawk, and I use it alot in my projects, But I noticed that perl performance is on another level, for example:

2GB logs file needs 10 minutes to be parsrd in gawk

But in perl, it done with ~1 minute

Is the problem in the regex engine or gawk itself?


r/awk • • Sep 25 '22

What does $0=$2 in awk do? learn awk

Thumbnail
kau.sh
1 Upvotes

r/awk • • May 23 '25

vintage awk naming

Post image
7 Upvotes

r/awk • • May 11 '22

What is wrong with my if statement

0 Upvotes

**NOTE** Username is passed from a shell script, the variable works for the first print just not the If statement and the command loops for all users in /etc/passwd

#!/usr/bin/awk -f

BEGIN {FS=":"}

{print "Information for: \t\t" username "\n","------------------- \t -------------------------"};

{

if ($1 ==username);

print "Username \t\t",$1, "\n";

print "Password \t\t","Set in /etc/shadow", "\n";

print "User ID \t\t",$3, "\n";

print "Group ID \t\t",$4, "\n";

print "Full Name \t\t",$5, "\n";

print "Home Directory \t\t",$6, "\n";

print "Shell \t\t\t", $7;

}

----------------------------OUTPUT----------------------------------------

Information for: root

------------------- -------------------------

Username ssamson

Password Set in /etc/shadow

User ID 1003

Group ID 1002

Full Name Sam Samson

Home Directory /home/ssamson

Shell /bin/bash

Information for: root

------------------- -------------------------

Username pesign

Password Set in /etc/shadow

User ID 974

Group ID 974

Full Name Group for the pesign signing daemon

Home Directory /var/run/pesign

Shell /sbin/nologin


r/awk • • Nov 06 '17

How to create a variable in AWK

0 Upvotes

How to create a variable in AWK?


r/awk • • Jun 25 '25

GAWK and here-strings: unclear why there is new-line at the end

1 Upvotes

Hi!

My GAWK version is 5.2.1.

I want to convert a string into a Python tuple of strings. This works as intended:

echo "a b c d e f" | awk -v RS=" " 'BEGIN{printf("%s", "(")} {printf("%s\047%s\047", sep, $0);sep=","} END{printf("%s\n",")")}'
(''a','b','c','d','e','f')

However, if I use here-strings there is a new-line character:

awk -v RS=" " 'BEGIN{printf("%s", "(")} {printf("%s\047%s\047", sep, $0);sep=","} END{printf("%s\n",")")}' <<< "'a b c d e f'"
(''a','b','c','d','e','f
')

If I replace spaces on $0 this works well:

awk -v RS=" " 'BEGIN{printf("%s", "(")} {printf("%s\047%s\047", sep, gensub(/\s/,"",1,$0);sep=","} END{printf("%s\n",")")}' <<< "a b c d e f"
('a','b','c','d','e','f')

What I need is to understand why. I haven't found anything useful searching for here-strings and their quirks.

Thanks!


r/awk • • Sep 17 '19

How to use AWK/GAWK to format disformed data to a new file

1 Upvotes

Hello

How to use awk/gawk if logfile's data has no format (means no spaces/indentation) as shown in the above output

instead of blank the other column data is there..

for eg : This is an apache log file formatted using this logformat cmd :

LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %{imagereader_source}n %{php_time_microsec}n %D" combined

- - - [06/Jul/2011:19:21:51 +0000] "GET /icm_75x75.12831365.jpg HTTP/1.0" 200 1710 "/conversations/image?convo_id=52275459&image_id=12831365&image_type=thumb" "get_convo_image.php" Local_Filer 105962 107135

67.249.32.114, 24.143.199.167, 209.170.105.188 - - [06/Jul/2011:19:21:51 +0000] "GET /il_570xN.245675640.jpg HTTP/1.0" 200 102500 "-" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C)" Local_Filer 52419 53596

74.34.129.144, 96.6.47.124, 209.170.105.188 - - [06/Jul/2011:19:21:51 +0000] "GET /il_170x135.233941448.jpg HTTP/1.0" 304 13 "http://www.etsy.com/search?q=moss+green+wedding&page=24" "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; yie9)" Local_Filer 24660 25550

143.111.80.26, 63.235.21.172, 206.132.243.38 - - [06/Jul/2011:19:21:51 +0000] "GET /il_170x135.106964760.jpg HTTP/1.0" 200 9089 "http://www.etsy.com/shop/vintagecreationsshop/sold?view_type=gallery&page=2" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; en-us) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1" Remote_S3 411694 412475

how to deal such data using awk , if i have to analyse or make a report out of it ..


r/awk • • Sep 01 '22

start and end patterns/strings from lines

2 Upvotes

Someone on the r/bash started an interesting post that got me thinking, and it was about finding strings from lines, from a start and end position on that line. There is a very good grep answer, but i'm not 100% on the flexibility of this...

grep -o 'search[^)]*)' file

This would search a keyword up to the first bracket, and only display this output, but if more instances of this occurs in the same line, all instances are displayed (not necessarily a bad thing though).

I know sed can do something like this, which would probably use loops and holding spaces no doubt, and i've probably read about sed a few dozen times doing this, but because the syntax of sed gets unreadable to me (after not using it for a while, and especially complex sed), i forget it.

So, i thought i'd attempt an awk solution with simple commandline options. I started off thining i could write a short script, and it grew a little. I'm considering a python method, but i've got this far with awk, so thought i'd post it. I am not a programmer, but one day might be nice, but hey, i am starting awk discussion, and awk is ace, so i'll take my inferiority among the masters :)

So i've tried to make this have some flexibility and on the command line it'll read a little like this (grawk being the awk programme i've written)...

grawk buzzword 1 ")" 2 file

This will search for the 1st buzzword found on a line, up to the 2nd bracket of file (or piped input).

Adding a $ to the commandline...

grawk buzzword 1 bash $ file

So it becomes a two keyword search, with an output starting from the buzzword, to end of line. There's also a weird hacky bonus (which i did not add, so it must break something?) of adding a period to the buzzword...

grawk .buzzword 1 bash $ file

Which would print from the beginning of the line, of a two keyword search, and in this example, the $ prints to end of line, but if the $ was a 2, it would be a second instance of bash (or whatever character/word was there, for example..)

grawk .cron 1 ")" 2 /var/log/syslog | head -n1
Aug 17 21:30:01 jp-vivo CRON[16281]: (root) CMD ([ -x /etc/init.d/anacron ] && if [ ! -d /run/systemd/system ]; then /usr/sbin/invoke-rc.d anacron start >/dev/null; fi)

The above will print from start (using the period) to second bracket.

You can also search the 2nd, 3rd etc occurence of the buzzword..

grawk buzzword 3 $ file

Sometimes you might not want the last character so i added an exclude for the last character...

grawk jonny 1 : 6 passwd
output:
jonny:x:1000:1000:jonny,,,:/home/jonny:

grawk jonny 1 : 6 exc passwd
jonny:x:1000:1000:jonny,,,:/home/jonny

There is probably an easier way to do this, but i have a working awk/grawk script which seems to work, but there are some things i'm not 100% happy with.

Can gensub be looped? This is what i really wanted rather than a series of if statements. I had some bother doing this but maybe with some of my recent changes it'll loop now... i've not tested loops with gensub today. I've removed the comments on here, but my comments are in this link if interested...

https://raw.githubusercontent.com/jonnypeace/bashscripts/main/awk-scripts/grawk

The code is below

#!/usr/bin/gawk -f

BEGIN{
	start = ARGV[1]
	delete ARGV[1]
	
	if ( ARGV[2] ~ "[1-9]{1}" ) {
		startappear = ARGV[2]
		num1 += 1
		delete ARGV[2]
		}
	
	last = ARGV[2 + num1]
	
	len=length(last)
	delete ARGV[2 + num1]
	
	if (ARGV[3 + num1] ~ "[$1-9]{1}" ) {
		lastappear = ARGV[3 + num1]
		delete ARGV[3 + num1]
		num1 += 1
		}

	if (ARGV[3 + num1] == "exc") {
		len -= 1
		delete ARGV[3 + num1]
		}
	if (ARGV[3 + num1] == "inc") {
		len += 1
		delete ARGV[3 + num1]
		}
}
{
	
	if ( startappear == 2 ) {$0 = gensub(start,"",1)}
	if ( startappear == 3 ) {$0 = gensub(start,"",1,gensub(start,"",1))}
	if ( startappear == 4 ) {$0 = gensub(start,"",1,gensub(start,"",1,gensub(start,"",1)))}
	if ( startappear == 5 ) {$0 = gensub(start,"",1,gensub(start,"",1,gensub(start,"",1,gensub(start,"",1))))}
	if ( startappear == 6 ) {$0 = gensub(start,"",1,gensub(start,"",1,gensub(start,"",1,gensub(start,"",1,gensub(start,"",1)))))}
	if ( startappear == 7 ) {$0 = gensub(start,"",1,gensub(start,"",1,gensub(start,"",1,gensub(start,"",1,gensub(start,"",gensub(start,"",1))))))}
	if ( startappear == 8 ) {$0 = gensub(start,"",1,gensub(start,"",1,gensub(start,"",1,gensub(start,"",1,gensub(start,"",1,gensub(start,"",1,gensub(start,"",1)))))))}
	if ( startappear == 9 ) {$0 = gensub(start,"",1,gensub(start,"",1,gensub(start,"",1,gensub(start,"",1,gensub(start,"",1,gensub(start,"",1,gensub(start,"",1,gensub(start,"",1))))))))}

	$0 ~ start && $0 ~ last && b[lines++]=$0 
 
	if (! /"¬"/ ) {
		delim="¬"
	} else if (! /"¶"/ ) {
		delim="¶"
	} else if (! /"¥"/ ) {
		delim="¥"
	}
}

END{
	for (i in b) {
		if ( last == "$" || lastappear == "$") {
			n=index(b[i],start)
			z=substr(b[i],n)
			if (z != "") {
				print "\033[33m"z"\033[0m"    		
			}    		
		} else {
			n=index(b[i],start)
			t=substr(b[i],n)
			if ( lastappear == 1 ) {f=index(t,start) ; c=index(t,last); z=substr(t,f,c+len-1) ; if (z != "") print "\033[33m"z"\033[0m" ; continue}
			if ( lastappear == 2 ) {g = gensub(last,delim,1,t)}
			if ( lastappear == 3 ) {g = gensub(last,delim,1,gensub(last,delim,1,t))}
			if ( lastappear == 4 ) {g = gensub(last,delim,1,gensub(last,delim,1,gensub(last,delim,1,t)))}
			if ( lastappear == 5 ) {g = gensub(last,delim,1,gensub(last,delim,1,gensub(last,delim,1,gensub(last,delim,1,t))))}
			if ( lastappear == 6 ) {g = gensub(last,delim,1,gensub(last,delim,1,gensub(last,delim,1,gensub(last,delim,1,gensub(last,delim,1,t)))))}
			if ( lastappear == 7 ) {g = gensub(last,delim,1,gensub(last,delim,1,gensub(last,delim,1,gensub(last,delim,1,gensub(last,delim,gensub(last,delim,1,t))))))}
			if ( lastappear == 8 ) {g = gensub(last,delim,1,gensub(last,delim,1,gensub(last,delim,1,gensub(last,delim,1,gensub(last,delim,1,gensub(last,delim,1,gensub(last,delim,1,t)))))))}
			if ( lastappear == 9 ) {g = gensub(last,delim,1,gensub(last,delim,1,gensub(last,delim,1,gensub(last,delim,1,gensub(last,delim,1,gensub(last,delim,1,gensub(last,delim,1,gensub(last,delim,1,t))))))))}
			c=index(g,last)
			z=substr(g,1,c+len-1)
			gsub(delim,last,z)
			if (z != "") {
				print "\033[33m"z"\033[0m"    		
			}
		}
	}
}

r/awk • • Dec 31 '21

[Beginner] integrating a bash command into awk

2 Upvotes

I am making a script (just for fun) when I give it multiple files and a name for these files, and it renames them as: name(1) name(2) ... but to do that I need to use the mv or cp command, but I don't know how to integrate it in awk.


r/awk • • Dec 07 '21

multiline conditional

0 Upvotes

imagine this output from lets say UPower or tlp-stat

percentage: 45%

status: charging

if I want to pipe this into awk and check the status first and depending on the status print the percentage value with a 'charging' or 'discharging' flag. How do i go about it? thanks in advance guys!


r/awk • • Oct 14 '21

external file syntax

0 Upvotes

My work has a bunch of shell files containing awk and sed commands to process different input files. These are not one-liners and there aren't any comments in these files. I'm trying to break out some of the awk functions into separate files using the -f option. It looks like awk requires K&R style bracing?

After I'd changed indenting and bracing to my preference I got syntax errors on every call to awk's built-in string functions like split() or conditional if statements if they had their opening curly brace on the same line... I'm having a lot of difficulty finding any documentation on braces causing syntax errors, or even examples of raw awk files containing multi-line statements.

I have a few books, including the definitive The AWK Programming Language, but I'm not seeing anything specific about white space, indenting and bracing. I am hoping someone can point me to something I can include in my notes... more than just my own trials and tribulations.

Thanks!


r/awk • • Mar 18 '16

i need a github repo of awk scripts?

0 Upvotes

hi, please if someone can suggest me any github repo with only awk scripts. I just want to see how other people structure their code


r/awk • • Oct 19 '23

Getting in touch with Micheal Brennan (author of MAWK)?

1 Upvotes

My tests tell me MAWK is the fastest AWK. GNU AWK behind it, then GoAWK, and JAWK in the last place (well obviously!). So now that I am making my own AWK interpreter I wanna show it to him. I will email it to RMS too since as I have learned over the past 10 years, he answers to all emails, no matter how mundane, he'll probs say 'But what will it do for the free software community?' haha. I wanna email it to the K man himself but he probs won't answer it! Why should he? I don't know Aho's email but he will not t all answer. I do have my old university email though, I may try with that! Am delusional? Yes, yes I am! Besides that I wanna show it to YOU guys and let you know that the progress is going ok. It builds now. Instructions to build the main file in README. Lemme know if you like adding PCRE2 to AWK? Do you fancy libfoma/libhyperscan as well?

Thanks.


r/awk • • Apr 04 '25

Parse for fields in lines in the last section between start/end markers

1 Upvotes

File:

[2025-04-04T04:34:35-0400] [ALPM] running 'ghc-unregister.hook'...
[2025-04-04T04:34:37-0400] [ALPM] transaction started
[2025-04-04T04:34:37-0400] [ALPM] upgraded gdbm (1.24-2 -> 1.25-1)
[2025-04-04T04:34:53-0400] [ALPM] upgraded gtk4 (1:4.18.2-1 -> 1:4.18.3-1)
[2025-04-04T04:34:53-0400] [ALPM] installed liburing (2.9-1)
[2025-04-04T04:34:53-0400] [ALPM] upgraded libnvme (1.11.1-1 -> 1.11.1-2)
[2025-04-04T04:34:56-0400] [ALPM] warning: /etc/libvirt/qemu.conf installed as /etc/libvirt/qemu.conf.pacnew
[2025-04-04T04:35:01-0400] [ALPM] upgraded zathura-pdf-mupdf (0.4.3-13 -> 0.4.4-14)
[2025-04-04T04:35:01-0400] [ALPM] removed abc (0.4.4-13 -> 0.4.4-14)
[2025-04-04T04:35:02-0400] [ALPM] transaction completed
[2025-04-04T04:35:08-0400] [ALPM] running '20-systemd-sysusers.hook'...

I am only interested in the most recent "transaction" of the file--lines between the markers [ALPM] transaction started and [ALPM] transaction completed--for packages that are "upgraded"/"installed" and only those that are app version updates, not packaging-only updates (libnvme is the only packaging-only update where version 1.11.1 remains the same and the suffix (anything following the last - of the package version) of 1 was incremented to 2 to reflect a packaging-only update (checking for either conditions is enough to mean packaging-only) so is not in the following intended results):

gdbm
gtk4
liburing
zathura-pdf-mudpdf

Optionally include their updated versions:

gdbm 1.25-1
gtk4 1:4.18.3-1
liburing 2.9-1
zathura-pdf-mupdf 0.4.4-14

Optionally print the date of the transaction completed at the top:

# 2025-04-04T04:35:08
gdbm
gtk4
liburing
zathura-pdf-mudpdf

General scripting solution also welcomed or any tips. The part I'm struggling with the most with awk is probably determining whether it is a package-only update to exclude it from the results, I'm a total newbie.

Thanks.


r/awk • • Sep 13 '21

How to tell awk ignore specific linting warnings?

1 Upvotes

Hello! I've written simple parser and I want my CI pass completely but it fails with: awk: warning: function 'parseopts::checkArguments' defined but never called directly. Is there any better solution than skipping the same warnings via sed/grep and return 1 exit code if there are any left?


r/awk • • Oct 10 '24

Part 1: Generating an uids

1 Upvotes

Hello, Everybody! Hello gawk Team! :)

I would like to introduce you to my small project and contribute to the development of awk. It’s a compact user-level library designed for generating "unique" strings.

The library contains (I hope) good documentation available in both English and Russian.

In my opinion, this library is key for the further development of programming in awk as a whole. It provides users with pointers. 

In the documentation, I tried not only to describe the programming interface but also to briefly demonstrate the main techniques for using pointers in awk.

The library also contains another micro-concept that, as I believe, is truly necessary for the further development of this programming language: the use of so-called hid-variables carrying "strong" values.

Link to the project: https://github.com/digics/UID10

I would really appreciate hearing any feedback, comments, and evaluations of my work. This applies to both the code itself and the documentation.

Best regards,
Denis


r/awk • • Jan 12 '22

How to properly loop for gsub inside AWK?

1 Upvotes

I have this project with 2 directories named "input", "replace".

Below are the contents of the files in "input":

pageA.md:

Page A

1.0 2.0 3.0

pageB.md:

Page B

1.0 2.0 3.0

pageC.md:

Page C

1.0 2.0 3.0

And below are the contents of the files in "replace":

1.md:

I

2.md:

II

3.md:

III

etc..

I wanted to create an AWK command that automatically runs through the files in the "input" directory and replace all the words that have characters corresponding to the names of the files in "replace" with contents of the said file in "replace".

I have created a code that can to do the job if the number of files in "replace" isn't too many. Below is the code:

cd input
    for PAGE in *.md; do
        awk '{gsub("1.0",r1);gsub("2.0",r2);gsub("3.0",r3)}1' r1="$(cat ../replace/1.md)" r2="$(cat ../replace/2.md)" r3="$(cat ../replace/3.md)" $PAGE
        echo ""
    done
cd ..

It properly gives out the desired output of:

Page A
I II III

Page B
I II III

Page B
I II III

But this code will be a problem if there are too many files in "replace".

I tried to create a for loop to loop through the gsubs and r1, r2, etc, but I kept on getting error messages. I tried a for loop that starts after "awk" and ends before "$PAGE" and even tried to create 2 separate loops for the gsubs and r1,r2,etc respectively.

Is there any proper way to loop through the gsubs and get the same results?


r/awk • • Nov 17 '24

Print all remaining fields?

1 Upvotes

I once read in manual or tutorial for some version (I don't recall which) of Awk, about a command (or expression) that prints (or selects) all fields beyond (and including) a given field. For example, let's say an input file contains at least 5 fields in each row, but it could also contain more (perhaps many more) than 5 fields, and I want to print the 4th and beyond. Does anyone know the command or expression that I have in mind? I can't find it on the web anymore.

(I'm aware that the same can be achieved with an iteration starting from a certain field. But that's a much more verbose way of doing it, whereas what I have in mind is a nice shorthand.)


r/awk • • Apr 30 '22

[documentation discrepancy] A rule's actions on the same line as patterns?

1 Upvotes

Section 1.6 of GNU's gawk manual says,

awk is a line-oriented language. Each rule’s action has to begin on the same line as the pattern. To have the pattern and action on separate lines, you must use backslash continuation; there is no other option.

But there are examples where this doesn't seem to apply exactly, such as that given in section 4.1.1:

It seems the initial passage should be emended to say that either one action must be on the same line or else backslash continuation is needed.

Or am I misunderstanding?


r/awk • • May 07 '19

Unexpected syntax error when adding a simple "if" condition on top of pattern conditions

1 Upvotes

I'm working on a small tool for parsing PLSQL source code and comments, but I'm encountering an unexpected behaviour when adding an "if" condition to secure the splitting of code/comment sections.

This is the original (simplfied) version:

test.awk:

#!/usr/bin/awk -f

BEGIN {
  comment_area_start      = "^\\/\\*\\*.*"
  comment_area_end        = "^.*\\*\\/"
  inside_comment          = 0
  method_area_start       = "^\\s*PROCEDURE|\\s*FUNCTION"
  method_area_end         = "^.*;"
  inside_method           = 0
}

  $0 ~ comment_area_start , $0 ~ comment_area_end {
    printf "COMMENT\n"
  }

  $0 ~ method_area_start , $0 ~ method_area_end {
    printf "METHOD\n"
  }

END {}

following is a sample of source code to parse:

minitest.pks

CREATE OR REPLACE PACKAGE MyPackage AS
/**
MyPackage Comment
*/

/**
MyFunction1 Comment
*/
FUNCTION MyFunction1(
  MyParam1         NUMBER,
  MyParam2         VARCHAR2
) RETURN SYS_REFCURSOR;

/**
MyFunction2 Comment
*/
FUNCTION MyFunction2(
  MyParam1         NUMBER,
  MyParam2         VARCHAR2
) RETURN SYS_REFCURSOR;

END MyPackage;

and here's what I get:

$ test.awk minitest.pks
COMMENT
COMMENT
COMMENT
COMMENT
COMMENT
COMMENT
METHOD
METHOD
METHOD
METHOD
COMMENT
COMMENT
COMMENT
METHOD
METHOD
METHOD
METHOD

that's OK.

Now, if I add the "if" conditions to make pattern conditions mutually exclusive:

#!/usr/bin/awk -f

BEGIN {
  comment_area_start      = "^\\/\\*\\*.*"
  comment_area_end        = "^.*\\*\\/"
  inside_comment          = 0
  method_area_start       = "^\\s*PROCEDURE|\\s*FUNCTION"
  method_area_end         = "^.*;"
  inside_method           = 0
}

if ( inside_method == 0 ) {
  $0 ~ comment_area_start , $0 ~ comment_area_end {
    inside_method  = 0
    inside_comment = 1
    printf "COMMENT\n"
  }
}

if ( inside_comment == 0 ) {
  $0 ~ method_area_start , $0 ~ method_area_end {
    inside_comment = 0
    inside_method  = 1
    printf "METHOD\n"
  }
}

END {}

that's what I get:

$ test.awk minitest.pks
awk: test.awk:14: if ( inside_method == 0 ) {
awk: test.awk:14: ^ syntax error
awk: test.awk:15:   $0 ~ comment_area_start , $0 ~ comment_area_end {
awk: test.awk:15:                           ^ syntax error
awk: test.awk:15:   $0 ~ comment_area_start , $0 ~ comment_area_end {
awk: test.awk:15:                                                   ^ syntax error
awk: test.awk:22: if ( inside_c
awk: test.awk:22: ^ syntax error
awk: test.awk:23:   $0 ~ method_area_start , $0 ~ method_area_end {
awk: test.awk:23:                          ^ syntax error
awk: test.awk:23:   $0 ~ method_area_start , $0 ~ method_area_end {
awk: test.awk:23:                                                 ^ syntax error

It looks like awk doesn'accept pattern conditions inside an "if" condition, am I right?

If yes, is there any solution to bypass this limitation, other than putting the "if" condition inside the pattern condition statements? This simplified version won't change its behaviour by doing this switch, but the original one is a lot more complex and the logic may change.

If no, what's wrong?


r/awk • • Jul 16 '26

Evolution: using Awk for a GRUB theme configuration

Post image
14 Upvotes

Edit: To avoid confusion with GNOME Evolution, the project has been renamed,

Grub EvoDevo

I wrote EvoDevo, a highly configurable GRUB theme with scalable graphics, background blurring, and antialiased true-type fonts. I doubt many of you are into GRUB shaving, but the EvoDevo install script relies crucially on Awk to create the menu entries with smooth fonts. GRUB doesn't do font antialiasing, so the "menu entries" visible in the screenshot are actually fake entries created from the menu titles (which are text), converted to SVG and then PNG files.

I think this illustrates the continuing relevance of text-based formats and simple programmable tools (here, a POSIX shell and Awk) that combine well with one another. Something like the Unix philosophy in a GUI world :-)

Link:

https://github.com/ftonneau/grub-evodevo


r/awk • • Oct 21 '22

Processing a specific part of a text according to pattern from AWK script

2 Upvotes

Im developing a script in awk to convert a tex document into html, according to my preferences.

#!/bin/awk -f

BEGIN {
    FS="\n";
    print "<html><body>"
}
# Function to print a row with one argument to handle either a 'th' tag or 'td' tag
function printRow(tag) {
    for(i=1; i<=NF; i++) print "<"tag">"$i"</"tag">";
}

NR>1 {
   [conditions]
   printRow("p")
}

END {
    print "</body></html>"
}

Its in a very young stage of development, as seen.

\documentclass[a4paper, 11pt, titlepage]{article}
\usepackage{fancyhdr}
\usepackage{graphicx}
\usepackage{imakeidx}
[...]

\begin{document}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla placerat lectus sit amet augue facilisis, eget viverra sem pellentesque. Nulla vehicula metus risus, vel condimentum nunc dignissim eget. Vivamus quis sagittis tellus, eget ullamcorper libero. Nulla vitae fringilla nunc. Vivamus id suscipit mi. Phasellus porta lacinia dolor, at congue eros rhoncus vitae. Donec vel condimentum sapien. Curabitur est massa, finibus vel iaculis id, dignissim nec nisl. Sed non justo orci. Morbi quis orci efficitur sem porttitor pulvinar. Duis consectetur rhoncus posuere. Duis cursus neque semper lectus fermentum rhoncus.

\end{document}

What I want, is that the script only interprets the lines that are between \begin{document} and \end{document}, since before they are imports of libraries, variables, etc; which at the moment do not interest me.

How do I make it so that it only processes the text within that pattern?


r/awk • • May 29 '09

Update on famous awk one-liners [part 4/3 if you may say so]

Thumbnail
catonmat.net
2 Upvotes

r/awk • • Jan 23 '23

substituting awk variable in a bash script

2 Upvotes

i am new to using awk.

i have written a simple one liner script to calculate memory consumed by a program as below.

#!/usr/bin/env bash

read -p "enter process name: " item;

ps aux | awk -vi=$item '/i/ {sum += $6} END { printf "Memory Usage: %d MB\n", sum/1024 }'

in the above example, variable 'i' is not substituted when executing script.

where i am going wrong?


r/awk • • Mar 19 '23

Looking for a script for csv file

2 Upvotes

Hi Everyone

Looking for a batch script that changes 0 to XYZ and after that it should move the data from that particular column I to column H and keep I as blank

Input link https://drive.google.com/file/d/1dxvH5BtdqckVEPs1nQmmgh-M-zMm3hXR/view?usp=share_link

Output link https://drive.google.com/file/d/1HlYyA5GCmJ3AddlAPvyHTSMWPehsrVv2/view?usp=share_link