Understand Awk Variables with 3 Practical Examples

\"\"

\"\" This article is part of the on-going Awk Tutorial and Examples series. Like any other programming languages, Awk also has user defined variables and built-in variables. In this article let us review how to define and use awk variables. Awk variables should begin with the letter, followed by it can consist of alpha numeric characters or underscore. Keywords […]

Read More: Awk Tutorial: Understand Awk Variables with 3 Practical Examples

\"Reblog

Seders\’s grab bag – Tutorials

http://sed.sourceforge.net/grabbag/tutorials/

seder\’s grab bag

Sed Tutorials

If you have written anything about sed – whether an introduction, how sed got you out of a real-life situation, or perhaps an advanced technique you\’ve discovered – you may like have your work published here. Your contribution will be very welcome.

Intros

sed one-liners (18kb)
The essential, official compendium of useful sed one-liners. Organised into sections by usage, such as file spacing, line numbering, selective line removal/deletion and optimisation.
The sed FAQ v15 (168kb)
The official, indispensable sed FAQ. This file was recently updated. Also available as ZIP-compressed HTML (75kb). The latest version can always be found on the author\’s site.
Another sed FAQ
And here is another sed FAQ, by a different person.
Do it with sed (51kb)
By Carlos Jorge G.Duarte. A comprehensive and leisurely résumé. Contains many interesting examples, and a useful command summary.
SED – A Non-interactive Text Editor (32kb)
By Lee E. McMahon (1978). The definitive introduction, this well-known document used to be distributed with UNIX systems. It examines each of sed\’s functions in depth and includes useful examples.
Program state in sed (4kb)
By Greg Ubben. A nice introduction to advanced sed, showing how to mantain state across lines.
Introduction to Unix\’s SED editor
By F. Curtis Michel, Rice University, Houston.

Advanced topics

Using sed to create a book index (12kb)
Eric Pement of Cornerstone magazine shows how he used sed and other utilities to massage an unsorted list of book references into an index.
Using lookup tables with s/// (9kb)
Part 1 of Greg Ubben\’s analysis of a complex sed script he wrote to sort, delimit and number an input file containing tabulated data. Lookup tables are a powerful technique for the serious seder\’s armoury.
A lookup-table counter (11kb)
Part 2 of Greg\’s script analysis looks at how he implemented a counter using lookup tables. This complex problem is described step by step from the basics, following through Greg\’s reasoning until we finally reach the solution.
Counting words (3kb)
Adding a list of decimals (3kb)
Greg explains how to count words and how to add a list of decimal numbers using a simple analog format.

Miscellaneous

When seemingly obvious scripts fail (2kb)
sed FAQ author Eric Pement explains why sometimes you cannot get your one-liner right.
Towers of Hanoi with sed (18kb)
A document which shows how to make sed solve the classic Towers of Hanoi game.
Proposals for a custom sed (18kb)
A list of proposals to make sed more versatile without sacrificing its speed and overall philosophy. I implemented a few of these in super-sed and in GNU sed 4.0.
\"Reblog

Perl script to create csv files with a pattern – Generic script.

I was having a really bad day and needed a quick solution to create some csv files. And this I needed to do for multiple data kinds and patterns, so I created this small script to do the job for me…

#Number of rows required in the output.

$rows = 100;

#The config and the output file

open (CF_FILE, \”<Config.test\”);
open (OUT_FILE, \”>test.csv\”);

#—————————————————————————
# No need to change anything below this.
#—————————————————————————

$count = 0 ;

#read a line from config file of the type

#also any line starting with # is treated as comment.

# startingvalue incrementvalue

# so you can have any number of fields here and all of them you would be joined with , to write to the output file.
while (<CF_FILE>)
{
/^#/ && next;
chomp();
@vars = split(/ /);
$arr[$count] = $vars[0];
$arr_inc[$count] = $vars[1];
$count++;
}
for ($i=0; $i < $rows; $i++)
{
$line = join (\”,\”,@arr);
print OUT_FILE \”$line\\n\”;
for ($j=0; $j < $count; $j++)
{
$arr[$j] += $arr_inc[$j];
}
}

\"Reblog