4259 links
  • Arnaud's links
  • Home
  • RSS Feed
  • Tag cloud
  • Login
search: tag:awk — newest first
  • shell - How to select lines between two marker patterns which may occur multiple times with awk/sed - Stack Overflow

    Use awk with a flag to trigger the print when necessary:

    $ awk '/abc/{flag=1;next}/mno/{flag=0}flag' file
    def1
    ghi1
    jkl1
    def2
    ghi2
    jkl2

    How does this work?

    /abc/ matches lines having this text, as well as /mno/ does.
    /abc/{flag=1;next} sets the flag when the text abc is found. Then, it skips the line.
    /mno/{flag=0} unsets the flag when the text mno is found.
    The final flag is a pattern with the default action, which is to print $0: if flag is equal 1 the line is printed.
    

    For a more detailed description and examples, together with cases when the patterns are either shown or not, see How to select lines between two patterns?.

    November 5, 2018 - permalink - https://stackoverflow.com/questions/17988756/how-to-select-lines-between-two-marker-patterns-which-may-occur-multiple-times-w
    awk
  • shell - bash / sh script to replace text between some tags/strings in a text file - Unix & Linux Stack Exchange

    Use

    sed '/#start/,/#end/replace_command'

    For example, if the file is called myconfig, and you want to replace "allow" with "deny" in that section, you could say

    sed '/#start/,/#end/s/allow/deny/' myconfig

    example

    sed -i -r "//,/<\/elasticConfig>/s,.+,false," file.xml

    October 12, 2017 - permalink - https://unix.stackexchange.com/questions/272061/bash-sh-script-to-replace-text-between-some-tags-strings-in-a-text-file
    awk replace sed
  • bash - median of column with awk - Stack Overflow

    This awk program assumes one column of numerically sorted data:

    /usr/bin/env awk

    {
    count[NR] = $1;
    }
    END {
    if (NR % 2) {
    print count[(NR + 1) / 2];
    } else {
    print (count[(NR / 2)] + count[(NR / 2) + 1]) / 2.0;
    }
    }

    Sample usage:

    sort -n data_file | awk -f median.awk

    August 2, 2016 - permalink - http://stackoverflow.com/questions/6166375/median-of-column-with-awk
    awk median nomarkdown
  • micha/jsawk
    September 18, 2015 - permalink - https://github.com/micha/jsawk
    awk grep json
  • ferd.ca -> Awk in 20 Minutes

    Ce tuto est bien fait
    Mais j'ai un peu de mal avec awk : pour des tâches simple je m'en sors avec cut, et pour des tâches plus complexes je passe à un vrai langage de scripting comme python

    January 18, 2015 - permalink - http://ferd.ca/awk-in-20-minutes.html
    awk
  • GNU Awk 4.1: Teaching an Old Bird Some New Tricks, Part II | Linux Journal
    January 1, 2015 - permalink - http://www.linuxjournal.com/content/gnu-awk-41-teaching-old-bird-some-new-tricks-part-ii
    awk
  • linux - Add up a column of numbers at the Unix shell - Stack Overflow

    | awk '{total = total + $1}END{print total}'

    find . ! -newer /tmp/file2015 -exec ls -l --block-size=M {} \; |cut -d' ' -f5|sed 's/M//'| awk '{total = total + $1}END{print total}'

    November 19, 2014 - permalink - http://stackoverflow.com/questions/926069/add-up-a-column-of-numbers-at-the-unix-shell
    add awk count sum total
  • Awk - A Tutorial and Introduction - by Bruce Barnett
    April 8, 2014 - permalink - http://www.grymoire.com/Unix/Awk.html#uh-0
    awk
  • The UNIX School: awk - 10 examples to split a file into multiple files

    exemple de split file avec awk

    December 16, 2013 - permalink - http://www.theunixschool.com/2012/06/awk-10-examples-to-split-file-into.html
    awk split
  • http://www.pement.org/awk/awk1line.txt
    November 2, 2013 - permalink - http://www.pement.org/awk/awk1line.txt
    awk memo