<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>text-processing on IT Quicktasks</title><link>https://quicktasks.ismael.casimpan.com/tags/text-processing/</link><description>Recent content in text-processing on IT Quicktasks</description><generator>Hugo -- gohugo.io</generator><copyright>Copyright © 2018–2022, Ismael Casimpan Jr.; All Rights Reserved</copyright><lastBuildDate>Tue, 24 Jan 2023 00:19:11 +0800</lastBuildDate><atom:link href="https://quicktasks.ismael.casimpan.com/tags/text-processing/index.xml" rel="self" type="application/rss+xml"/><item><title>Awk Variable Value from Bash</title><link>https://quicktasks.ismael.casimpan.com/post/awk-variable-value-from-bash/</link><pubDate>Tue, 24 Jan 2023 00:19:11 +0800</pubDate><guid>https://quicktasks.ismael.casimpan.com/post/awk-variable-value-from-bash/</guid><description>
Suppose you have a bash script that wants to pass a value to an awk line. You would do something like this:
1awk -v today=&amp;#34;$(date)&amp;#34; &amp;#39;BEGIN {print today}&amp;#39; Key above is the -v in awk which can be repeated as there are variables to assign. See man awk for details.
If you put it into the awk body, (outside BEGIN), you need to terminate it with &amp;lt;&amp;lt;&amp;lt;/dev/null. Otherwise, it will wait for indefinite input.</description></item><item><title>Save Separate Columns Into Separate Files using Awk</title><link>https://quicktasks.ismael.casimpan.com/post/awk-save-columns-into-separate-files/</link><pubDate>Tue, 24 Jan 2023 00:19:11 +0800</pubDate><guid>https://quicktasks.ismael.casimpan.com/post/awk-save-columns-into-separate-files/</guid><description>
Assume that you have a column of data and you want to separate each column into it's own file.
It's relatively easy in awk.
Input is a sha256 or hash of ebooks:
1~$ sha256sum *.pdf 29scac1ae26617a210e2211cce308aa2b770b08cb51f46621b13be272877cc068 ebook1.pdf 3edbd3d4419878ee9ab68b211fc69e145eb776309273ab467e2f1bdc912d0252a ebook2.pdf and script is as follows:
1~$ sha256sum *.pdf|awk &amp;#39;{ 2for(i=1;i&amp;lt;=NF;i++) print $i &amp;gt; (&amp;#34;temp_hash&amp;#34; i) 3}&amp;#39; It produces two file outputs (since we only have two columns.
temp_hash1 - containing the first column (or the hash</description></item><item><title>Swap Every Two Lines in Text File using Awk</title><link>https://quicktasks.ismael.casimpan.com/post/awk-swap-every-2-lines/</link><pubDate>Tue, 24 Jan 2023 00:19:11 +0800</pubDate><guid>https://quicktasks.ismael.casimpan.com/post/awk-swap-every-2-lines/</guid><description>
This swaps every two lines of input.
Given this input.txt
1wan 2tew 3free 4phore Ouput the following:
1tew 2wan 3phore 4free Full command to run:
1~$ cat input.txt | awk &amp;#39;{ 2if ((getline tmp) &amp;gt; 0) { 3print tmp 4print $0 5} else 6print $0 7}&amp;#39; CREDITS: https://www.math.utah.edu/docs/info/gawk_6.html</description></item></channel></rss>