LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Blogs > Here are some things which I hope will be helpful.
User Name
Password

Notices

Any code I post here should be considered experimental and unfinished. Don't use it in a production environment. It is your own responsibility to evaluate the code's fitness for any purpose. Programming isn't done in a vacuum, so be prepared to do your own research and teach yourself to do better.

Most importantly, all your polite critiques, elaborations, and corrections are heartily welcomed.
programming my solutions to various problems in various languages
Old

Selecting fields from a line using "sed"

Posted 12-25-2011 at 12:51 AM by Telengard (Here are some things which I hope will be helpful.)
Updated 12-26-2011 at 10:24 PM by Telengard
Tags sed

Yeah, sed ...

No matter how well I think I know sed, it still manages to bite me more often than serve me. Everything I do know about sed, manuals aside, I learned from other programs like ed, vi, and even awk. What I'm getting to is this: my sed-fu is weak, so don't take anything I say about it at face value. Do your own research and learn better for yourself (which you ought to do regardless).

About portability

I'll be using the --posix option with GNU sed...
Member
Views 3776 Comments 0 Telengard is offline
Old

Selecting fields from a line using "cut"

Posted 12-22-2011 at 06:56 PM by Telengard (Here are some things which I hope will be helpful.)
Updated 12-26-2011 at 10:26 PM by Telengard
Tags cut

using cut to break down text

You can use cut to grab only the data you want from a line of text. Tell cut which groups of characters you are interested in and it will print them. By default cut uses tab characters to break down groups of text from the input file.

NOTE: In the example data files which follow, the strings <TAB> and <SPACE> shall be used to visually distinguish whitespace characters. A tab character is the character generated when you press the...
Member
Views 2917 Comments 0 Telengard is offline
Old

How to kill lines before and after a pattern

Posted 12-21-2011 at 05:45 PM by Telengard (Here are some things which I hope will be helpful.)
Updated 12-21-2011 at 06:27 PM by Telengard
Tags awk

PHP Code:
#! /usr/bin/awk -f

# Deletes n lines before pattern and m lines after.
# Intended to be portable.
# It is your own responsibility to evaluate the fitness of this program.

BEGIN {
    
# set the following initializers as you please
    # FS=" "
    # OFS=" "
    
n=5
    m
=3
}

/
line 11/ { # insert your desired regex "pattern" between the slashes
    
pattern_line=FNR 
...
Member
Posted in programming
Views 814 Comments 0 Telengard is offline

  



All times are GMT -5. The time now is 08:56 PM.

Main Menu
Advertisement

My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration