yannstatic/static/2020/02/08/grep-awk-sed.html

3639 lines
265 KiB
HTML
Raw Permalink Normal View History

2024-10-31 20:18:37 +01:00
<!DOCTYPE html><html lang="fr">
<head><meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"><title>grep - awk - sed - YannStatic</title>
<meta name="description" content="grep">
<link rel="canonical" href="https://static.rnmkcy.eu/2020/02/08/grep-awk-sed.html"><link rel="alternate" type="application/rss+xml" title="YannStatic" href="/feed.xml">
<!-- - include head/favicon.html - -->
<link rel="shortcut icon" type="image/png" href="/assets/favicon/favicon.png"><link rel="stylesheet" href="/assets/css/main.css"><link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css" ><!-- start custom head snippets --><link rel="stylesheet" href="/assets/css/expand.css">
<!-- end custom head snippets --><script>(function() {
window.isArray = function(val) {
return Object.prototype.toString.call(val) === '[object Array]';
};
window.isString = function(val) {
return typeof val === 'string';
};
window.hasEvent = function(event) {
return 'on'.concat(event) in window.document;
};
window.isOverallScroller = function(node) {
return node === document.documentElement || node === document.body || node === window;
};
window.isFormElement = function(node) {
var tagName = node.tagName;
return tagName === 'INPUT' || tagName === 'SELECT' || tagName === 'TEXTAREA';
};
window.pageLoad = (function () {
var loaded = false, cbs = [];
window.addEventListener('load', function () {
var i;
loaded = true;
if (cbs.length > 0) {
for (i = 0; i < cbs.length; i++) {
cbs[i]();
}
}
});
return {
then: function(cb) {
cb && (loaded ? cb() : (cbs.push(cb)));
}
};
})();
})();
(function() {
window.throttle = function(func, wait) {
var args, result, thisArg, timeoutId, lastCalled = 0;
function trailingCall() {
lastCalled = new Date;
timeoutId = null;
result = func.apply(thisArg, args);
}
return function() {
var now = new Date,
remaining = wait - (now - lastCalled);
args = arguments;
thisArg = this;
if (remaining <= 0) {
clearTimeout(timeoutId);
timeoutId = null;
lastCalled = now;
result = func.apply(thisArg, args);
} else if (!timeoutId) {
timeoutId = setTimeout(trailingCall, remaining);
}
return result;
};
};
})();
(function() {
var Set = (function() {
var add = function(item) {
var i, data = this._data;
for (i = 0; i < data.length; i++) {
if (data[i] === item) {
return;
}
}
this.size ++;
data.push(item);
return data;
};
var Set = function(data) {
this.size = 0;
this._data = [];
var i;
if (data.length > 0) {
for (i = 0; i < data.length; i++) {
add.call(this, data[i]);
}
}
};
Set.prototype.add = add;
Set.prototype.get = function(index) { return this._data[index]; };
Set.prototype.has = function(item) {
var i, data = this._data;
for (i = 0; i < data.length; i++) {
if (this.get(i) === item) {
return true;
}
}
return false;
};
Set.prototype.is = function(map) {
if (map._data.length !== this._data.length) { return false; }
var i, j, flag, tData = this._data, mData = map._data;
for (i = 0; i < tData.length; i++) {
for (flag = false, j = 0; j < mData.length; j++) {
if (tData[i] === mData[j]) {
flag = true;
break;
}
}
if (!flag) { return false; }
}
return true;
};
Set.prototype.values = function() {
return this._data;
};
return Set;
})();
window.Lazyload = (function(doc) {
var queue = {js: [], css: []}, sources = {js: {}, css: {}}, context = this;
var createNode = function(name, attrs) {
var node = doc.createElement(name), attr;
for (attr in attrs) {
if (attrs.hasOwnProperty(attr)) {
node.setAttribute(attr, attrs[attr]);
}
}
return node;
};
var end = function(type, url) {
var s, q, qi, cbs, i, j, cur, val, flag;
if (type === 'js' || type ==='css') {
s = sources[type], q = queue[type];
s[url] = true;
for (i = 0; i < q.length; i++) {
cur = q[i];
if (cur.urls.has(url)) {
qi = cur, val = qi.urls.values();
qi && (cbs = qi.callbacks);
for (flag = true, j = 0; j < val.length; j++) {
cur = val[j];
if (!s[cur]) {
flag = false;
}
}
if (flag && cbs && cbs.length > 0) {
for (j = 0; j < cbs.length; j++) {
cbs[j].call(context);
}
qi.load = true;
}
}
}
}
};
var load = function(type, urls, callback) {
var s, q, qi, node, i, cur,
_urls = typeof urls === 'string' ? new Set([urls]) : new Set(urls), val, url;
if (type === 'js' || type ==='css') {
s = sources[type], q = queue[type];
for (i = 0; i < q.length; i++) {
cur = q[i];
if (_urls.is(cur.urls)) {
qi = cur;
break;
}
}
val = _urls.values();
if (qi) {
callback && (qi.load || qi.callbacks.push(callback));
callback && (qi.load && callback());
} else {
q.push({
urls: _urls,
callbacks: callback ? [callback] : [],
load: false
});
for (i = 0; i < val.length; i++) {
node = null, url = val[i];
if (s[url] === undefined) {
(type === 'js' ) && (node = createNode('script', { src: url }));
(type === 'css') && (node = createNode('link', { rel: 'stylesheet', href: url }));
if (node) {
node.onload = (function(type, url) {
return function() {
end(type, url);
};
})(type, url);
(doc.head || doc.body).appendChild(node);
s[url] = false;
}
}
}
}
}
};
return {
js: function(url, callback) {
load('js', url, callback);
},
css: function(url, callback) {
load('css', url, callback);
}
};
})(this.document);
})();
</script><script>
(function() {
var TEXT_VARIABLES = {
version: '2.2.6',
sources: {
font_awesome: 'https://use.fontawesome.com/releases/v5.0.13/css/all.css',
jquery: '/assets/js/jquery.min.js',
leancloud_js_sdk: '//cdn.jsdelivr.net/npm/leancloud-storage@3.13.2/dist/av-min.js',
chart: 'https://cdn.bootcss.com/Chart.js/2.7.2/Chart.bundle.min.js',
gitalk: {
js: 'https://cdn.bootcss.com/gitalk/1.2.2/gitalk.min.js',
css: 'https://cdn.bootcss.com/gitalk/1.2.2/gitalk.min.css'
},
valine: 'https://unpkg.com/valine/dist/Valine.min.js'
},
site: {
toc: {
selectors: 'h1,h2,h3'
}
},
paths: {
search_js: '/assets/search.js'
}
};
window.TEXT_VARIABLES = TEXT_VARIABLES;
})();
</script>
</head>
<body>
<div class="root" data-is-touch="false">
<div class="layout--page js-page-root">
<!----><div class="page__main js-page-main page__viewport hide-footer has-aside has-aside cell cell--auto">
<div class="page__main-inner">
<div class="page__header d-print-none">
<header class="header"><div class="main">
<div class="header__title">
<div class="header__brand">
<svg id="svg" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="400" height="478.9473684210526" viewbox="0, 0, 400,478.9473684210526"><g id="svgg"><path id="path0" d="M308.400 56.805 C 306.970 56.966,303.280 57.385,300.200 57.738 C 290.906 58.803,278.299 59.676,269.200 59.887 L 260.600 60.085 259.400 61.171 C 258.010 62.428,256.198 63.600,255.645 63.600 C 255.070 63.600,252.887 65.897,252.598 66.806 C 252.460 67.243,252.206 67.600,252.034 67.600 C 251.397 67.600,247.206 71.509,247.202 72.107 C 247.201 72.275,246.390 73.190,245.400 74.138 C 243.961 75.517,243.598 76.137,243.592 77.231 C 243.579 79.293,241.785 83.966,240.470 85.364 C 239.176 86.740,238.522 88.365,237.991 91.521 C 237.631 93.665,236.114 97.200,235.554 97.200 C 234.938 97.200,232.737 102.354,232.450 104.472 C 232.158 106.625,230.879 109.226,229.535 110.400 C 228.933 110.926,228.171 113.162,226.434 119.500 C 226.178 120.435,225.795 121.200,225.584 121.200 C 225.373 121.200,225.200 121.476,225.200 121.813 C 225.200 122.149,224.885 122.541,224.500 122.683 C 223.606 123.013,223.214 123.593,223.204 124.600 C 223.183 126.555,220.763 132.911,219.410 134.562 C 218.443 135.742,217.876 136.956,217.599 138.440 C 217.041 141.424,215.177 146.434,214.532 146.681 C 214.240 146.794,214.000 147.055,214.000 147.261 C 214.000 147.467,213.550 148.086,213.000 148.636 C 212.450 149.186,212.000 149.893,212.000 150.208 C 212.000 151.386,208.441 154.450,207.597 153.998 C 206.319 153.315,204.913 150.379,204.633 147.811 C 204.365 145.357,202.848 142.147,201.759 141.729 C 200.967 141.425,199.200 137.451,199.200 135.974 C 199.200 134.629,198.435 133.224,196.660 131.311 C 195.363 129.913,194.572 128.123,193.870 125.000 C 193.623 123.900,193.236 122.793,193.010 122.540 C 190.863 120.133,190.147 118.880,188.978 115.481 C 188.100 112.928,187.151 111.003,186.254 109.955 C 185.358 108.908,184.518 107.204,183.847 105.073 C 183.280 103.273,182.497 101.329,182.108 100.753 C 181.719 100.177,180.904 98.997,180.298 98.131 C 179.693 97.265,178.939 95.576,178.624 94.378 C 178.041 92.159,177.125 90.326,175.023 87.168 C 174.375 86.196,173.619 84.539,173.342 83.486 C 172.800 81.429,171.529 79.567,170.131 78.785 C 169.654 78.517,168.697 77.511,168.006 76.549 C 167.316 75.587,166.594 74.800,166.402 74.800 C 166.210 74.800,164.869 73.633,163.421 72.206 C 160.103 68.936,161.107 69.109,146.550 69.301 C 133.437 69.474,128.581 70.162,126.618 72.124 C 126.248 72.495,125.462 72.904,124.872 73.033 C 124.282 73.163,123.088 73.536,122.219 73.863 C 121.349 74.191,119.028 74.638,117.061 74.858 C 113.514 75.254,109.970 76.350,108.782 77.419 C 107.652 78.436,100.146 80.400,97.388 80.400 C 95.775 80.400,93.167 81.360,91.200 82.679 C 90.430 83.195,89.113 83.804,88.274 84.031 C 85.875 84.681,78.799 90.910,74.400 96.243 L 73.400 97.456 73.455 106.028 C 73.526 117.055,74.527 121.238,77.820 124.263 C 78.919 125.273,80.400 127.902,80.400 128.842 C 80.400 129.202,81.075 130.256,81.900 131.186 C 83.563 133.059,85.497 136.346,86.039 138.216 C 86.233 138.886,87.203 140.207,88.196 141.153 C 89.188 142.098,90.000 143.104,90.000 143.388 C 90.000 144.337,92.129 148.594,92.869 149.123 C 93.271 149.410,93.600 149.831,93.600 150.059 C 93.600 150.286,93.932 150.771,94.337 151.136 C 94.743 151.501,95.598 153.004,96.237 154.475 C 96.877 155.947,97.760 157.351,98.200 157.596 C 98.640 157.841,99.900 159.943,101.000 162.267 C 102.207 164.817,103.327 166.644,103.825 166.876 C 104.278 167.087,105.065 168.101,105.573 169.130 C 107.658 173.348,108.097 174.093,110.006 176.647 C 111.103 178.114,112.000 179.725,112.000 180.227 C 112.000 181.048,113.425 183.163,114.678 184.200 C 115.295 184.711,117.396 188.733,117.720 190.022 C 117.855 190.562,118.603 191.633,119.381 192.402 C 120.160 193.171,121.496 195.258,122.351 197.039 C 123.206 198.820,124.167 200.378,124.487 200.501 C 124.807 200.624,125.953 202.496,127.034 204.662 C 128.114 206.828,129.676 209.299,130.505 210.153 C 131.333 211.007,132.124 212.177,132.262 212.753 C 132.618 214.239,134.291 217.048,136.288 219.516 C 137.230 220.679,138.000 221.92
" href="/">YannStatic</a>
</div>
<!--<button class="button button--secondary button--circle search-button js-search-toggle"><i class="fas fa-search"></i></button>--><!-- <li><button class="button button--secondary button--circle search-button js-search-toggle"><i class="fas fa-search"></i></button></li> -->
<!-- Champ de recherche -->
<div id="searchbox" class="search search--dark" style="visibility: visible">
<div class="main">
<div class="search__header"></div>
<div class="search-bar">
<div class="search-box js-search-box">
<div class="search-box__icon-search"><i class="fas fa-search"></i></div>
<input id="search-input" type="text">
<!-- <div class="search-box__icon-clear js-icon-clear">
<a><i class="fas fa-times"></i></a>
</div> -->
</div>
</div>
</div>
</div>
<!-- Script pointing to search-script.js -->
<script>/*!
* Simple-Jekyll-Search
* Copyright 2015-2020, Christian Fei
* Licensed under the MIT License.
*/
(function(){
'use strict'
var _$Templater_7 = {
compile: compile,
setOptions: setOptions
}
const options = {}
options.pattern = /\{(.*?)\}/g
options.template = ''
options.middleware = function () {}
function setOptions (_options) {
options.pattern = _options.pattern || options.pattern
options.template = _options.template || options.template
if (typeof _options.middleware === 'function') {
options.middleware = _options.middleware
}
}
function compile (data) {
return options.template.replace(options.pattern, function (match, prop) {
const value = options.middleware(prop, data[prop], options.template)
if (typeof value !== 'undefined') {
return value
}
return data[prop] || match
})
}
'use strict';
function fuzzysearch (needle, haystack) {
var tlen = haystack.length;
var qlen = needle.length;
if (qlen > tlen) {
return false;
}
if (qlen === tlen) {
return needle === haystack;
}
outer: for (var i = 0, j = 0; i < qlen; i++) {
var nch = needle.charCodeAt(i);
while (j < tlen) {
if (haystack.charCodeAt(j++) === nch) {
continue outer;
}
}
return false;
}
return true;
}
var _$fuzzysearch_1 = fuzzysearch;
'use strict'
/* removed: const _$fuzzysearch_1 = require('fuzzysearch') */;
var _$FuzzySearchStrategy_5 = new FuzzySearchStrategy()
function FuzzySearchStrategy () {
this.matches = function (string, crit) {
return _$fuzzysearch_1(crit.toLowerCase(), string.toLowerCase())
}
}
'use strict'
var _$LiteralSearchStrategy_6 = new LiteralSearchStrategy()
function LiteralSearchStrategy () {
this.matches = function (str, crit) {
if (!str) return false
str = str.trim().toLowerCase()
crit = crit.trim().toLowerCase()
return crit.split(' ').filter(function (word) {
return str.indexOf(word) >= 0
}).length === crit.split(' ').length
}
}
'use strict'
var _$Repository_4 = {
put: put,
clear: clear,
search: search,
setOptions: __setOptions_4
}
/* removed: const _$FuzzySearchStrategy_5 = require('./SearchStrategies/FuzzySearchStrategy') */;
/* removed: const _$LiteralSearchStrategy_6 = require('./SearchStrategies/LiteralSearchStrategy') */;
function NoSort () {
return 0
}
const data = []
let opt = {}
opt.fuzzy = false
opt.limit = 10
opt.searchStrategy = opt.fuzzy ? _$FuzzySearchStrategy_5 : _$LiteralSearchStrategy_6
opt.sort = NoSort
opt.exclude = []
function put (data) {
if (isObject(data)) {
return addObject(data)
}
if (isArray(data)) {
return addArray(data)
}
return undefined
}
function clear () {
data.length = 0
return data
}
function isObject (obj) {
return Boolean(obj) && Object.prototype.toString.call(obj) === '[object Object]'
}
function isArray (obj) {
return Boolean(obj) && Object.prototype.toString.call(obj) === '[object Array]'
}
function addObject (_data) {
data.push(_data)
return data
}
function addArray (_data) {
const added = []
clear()
for (let i = 0, len = _data.length; i < len; i++) {
if (isObject(_data[i])) {
added.push(addObject(_data[i]))
}
}
return added
}
function search (crit) {
if (!crit) {
return []
}
return findMatches(data, crit, opt.searchStrategy, opt).sort(opt.sort)
}
function __setOptions_4 (_opt) {
opt = _opt || {}
opt.fuzzy = _opt.fuzzy || false
opt.limit = _opt.limit || 10
opt.searchStrategy = _opt.fuzzy ? _$FuzzySearchStrategy_5 : _$LiteralSearchStrategy_6
opt.sort = _opt.sort || NoSort
opt.exclude = _opt.exclude || []
}
function findMatches (data, crit, strategy, opt) {
const matches = []
for (let i = 0; i < data.length && matches.length < opt.limit; i++) {
const match = findMatchesInObject(data[i], crit, strategy, opt)
if (match) {
matches.push(match)
}
}
return matches
}
function findMatchesInObject (obj, crit, strategy, opt) {
for (const key in obj) {
if (!isExcluded(obj[key], opt.exclude) && strategy.matches(obj[key], crit)) {
return obj
}
}
}
function isExcluded (term, excludedTerms) {
for (let i = 0, len = excludedTerms.length; i < len; i++) {
const excludedTerm = excludedTerms[i]
if (new RegExp(excludedTerm).test(term)) {
return true
}
}
return false
}
/* globals ActiveXObject:false */
'use strict'
var _$JSONLoader_2 = {
load: load
}
function load (location, callback) {
const xhr = getXHR()
xhr.open('GET', location, true)
xhr.onreadystatechange = createStateChangeListener(xhr, callback)
xhr.send()
}
function createStateChangeListener (xhr, callback) {
return function () {
if (xhr.readyState === 4 && xhr.status === 200) {
try {
callback(null, JSON.parse(xhr.responseText))
} catch (err) {
callback(err, null)
}
}
}
}
function getXHR () {
return window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP')
}
'use strict'
var _$OptionsValidator_3 = function OptionsValidator (params) {
if (!validateParams(params)) {
throw new Error('-- OptionsValidator: required options missing')
}
if (!(this instanceof OptionsValidator)) {
return new OptionsValidator(params)
}
const requiredOptions = params.required
this.getRequiredOptions = function () {
return requiredOptions
}
this.validate = function (parameters) {
const errors = []
requiredOptions.forEach(function (requiredOptionName) {
if (typeof parameters[requiredOptionName] === 'undefined') {
errors.push(requiredOptionName)
}
})
return errors
}
function validateParams (params) {
if (!params) {
return false
}
return typeof params.required !== 'undefined' && params.required instanceof Array
}
}
'use strict'
var _$utils_9 = {
merge: merge,
isJSON: isJSON
}
function merge (defaultParams, mergeParams) {
const mergedOptions = {}
for (const option in defaultParams) {
mergedOptions[option] = defaultParams[option]
if (typeof mergeParams[option] !== 'undefined') {
mergedOptions[option] = mergeParams[option]
}
}
return mergedOptions
}
function isJSON (json) {
try {
if (json instanceof Object && JSON.parse(JSON.stringify(json))) {
return true
}
return false
} catch (err) {
return false
}
}
var _$src_8 = {};
(function (window) {
'use strict'
let options = {
searchInput: null,
resultsContainer: null,
json: [],
success: Function.prototype,
searchResultTemplate: '<li><a href="{url}" title="{desc}">{title}</a></li>',
templateMiddleware: Function.prototype,
sortMiddleware: function () {
return 0
},
noResultsText: 'No results found',
limit: 10,
fuzzy: false,
debounceTime: null,
exclude: []
}
let debounceTimerHandle
const debounce = function (func, delayMillis) {
if (delayMillis) {
clearTimeout(debounceTimerHandle)
debounceTimerHandle = setTimeout(func, delayMillis)
} else {
func.call()
}
}
const requiredOptions = ['searchInput', 'resultsContainer', 'json']
/* removed: const _$Templater_7 = require('./Templater') */;
/* removed: const _$Repository_4 = require('./Repository') */;
/* removed: const _$JSONLoader_2 = require('./JSONLoader') */;
const optionsValidator = _$OptionsValidator_3({
required: requiredOptions
})
/* removed: const _$utils_9 = require('./utils') */;
window.SimpleJekyllSearch = function (_options) {
const errors = optionsValidator.validate(_options)
if (errors.length > 0) {
throwError('You must specify the following required options: ' + requiredOptions)
}
options = _$utils_9.merge(options, _options)
_$Templater_7.setOptions({
template: options.searchResultTemplate,
middleware: options.templateMiddleware
})
_$Repository_4.setOptions({
fuzzy: options.fuzzy,
limit: options.limit,
sort: options.sortMiddleware,
exclude: options.exclude
})
if (_$utils_9.isJSON(options.json)) {
initWithJSON(options.json)
} else {
initWithURL(options.json)
}
const rv = {
search: search
}
typeof options.success === 'function' && options.success.call(rv)
return rv
}
function initWithJSON (json) {
_$Repository_4.put(json)
registerInput()
}
function initWithURL (url) {
_$JSONLoader_2.load(url, function (err, json) {
if (err) {
throwError('failed to get JSON (' + url + ')')
}
initWithJSON(json)
})
}
function emptyResultsContainer () {
options.resultsContainer.innerHTML = ''
}
function appendToResultsContainer (text) {
options.resultsContainer.innerHTML += text
}
function registerInput () {
options.searchInput.addEventListener('input', function (e) {
if (isWhitelistedKey(e.which)) {
emptyResultsContainer()
debounce(function () { search(e.target.value) }, options.debounceTime)
}
})
}
function search (query) {
if (isValidQuery(query)) {
emptyResultsContainer()
render(_$Repository_4.search(query), query)
}
}
function render (results, query) {
const len = results.length
if (len === 0) {
return appendToResultsContainer(options.noResultsText)
}
for (let i = 0; i < len; i++) {
results[i].query = query
appendToResultsContainer(_$Templater_7.compile(results[i]))
}
}
function isValidQuery (query) {
return query && query.length > 0
}
function isWhitelistedKey (key) {
return [13, 16, 20, 37, 38, 39, 40, 91].indexOf(key) === -1
}
function throwError (message) {
throw new Error('SimpleJekyllSearch --- ' + message)
}
})(window)
}());
</script>
<!-- Configuration -->
<script>
SimpleJekyllSearch({
searchInput: document.getElementById('search-input'),
resultsContainer: document.getElementById('results-container'),
json: '/search.json',
//searchResultTemplate: '<li><a href="https://static.rnmkcy.eu{url}">{date}&nbsp;{title}</a></li>'
searchResultTemplate: '<li><a href="{url}">{date}&nbsp;{title}</a></li>'
})
</script>
<!-- Fin déclaration champ de recherche -->
</div>
<nav class="navigation">
<ul>
<li class="navigation__item"><a href="/archive.html">Etiquettes</a></li>
<li class="navigation__item"><a href="/htmldoc.html">Documents</a></li>
<li class="navigation__item"><a href="/liens_ttrss.html">Liens</a></li>
<li class="navigation__item"><a href="/aide-jekyll-text-theme.html">Aide</a></li>
</ul>
</nav>
</div>
</header>
</div>
<div class="page__content"><div class="main"><div class="grid grid--reverse">
<div class="col-main cell cell--auto">
<!-- start custom main top snippet --><div id="results-container" class="search-result js-search-result"></div>
<!-- end custom main top snippet -->
<article itemscope itemtype="http://schema.org/Article"><div class="article__header"><header><h1 style="color:Tomato;">grep - awk - sed</h1></header></div>
<meta itemprop="headline" content="grep - awk - sed">
<div class="article__info clearfix">
<ul class="left-col menu"><li>
2024-11-08 14:10:33 +01:00
<a class="button button--secondary button--pill button--sm" style="color:#00FFFF" href="/archive.html?tag=commande">commande</a>
2024-10-31 20:18:37 +01:00
</li></ul>
<ul class="right-col menu"><li>
<i class="far fa-calendar-alt"></i> <span title="Création" style="color:#FF00FF"> 8 févr. 2020</span>
<span title="Modification" style="color:#00FF7F">26 juil. 2020</span>
</li></ul>
</div>
<meta itemprop="datePublished" content="2020-07-26T00:00:00+02:00">
<meta itemprop="keywords" content="commande">
<div class="js-article-content">
<div class="layout--article">
<!-- start custom article top snippet -->
<style>
#myBtn {
display: none;
position: fixed;
bottom: 10px;
right: 10px;
z-index: 99;
font-size: 12px;
font-weight: bold;
border: none;
outline: none;
background-color: white;
color: black;
cursor: pointer;
padding: 5px;
border-radius: 4px;
}
#myBtn:hover {
background-color: #555;
}
</style>
<button onclick="topFunction()" id="myBtn" title="Haut de page"></button>
<script>
//Get the button
var mybutton = document.getElementById("myBtn");
// When the user scrolls down 20px from the top of the document, show the button
window.onscroll = function() {scrollFunction()};
function scrollFunction() {
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
mybutton.style.display = "block";
} else {
mybutton.style.display = "none";
}
}
// When the user clicks on the button, scroll to the top of the document
function topFunction() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
}
</script>
<!-- end custom article top snippet -->
<div class="article__content" itemprop="articleBody">
<details>
<summary><b>Afficher/cacher Sommaire</b></summary>
<!-- affichage sommaire -->
<div class="toc-aside js-toc-root"></div>
</details><h2 id="grep">grep</h2>
<p><em>La commande grep chaîne fichier permet dextraire de fichier toutes les lignes</em></p>
<ul>
<li><a href="https://www.startpage.com/do/dsearch?query=linux+commande+grep&amp;cat=web&amp;pl=opensearch&amp;language=francais">Recherche du mot “grep”</a></li>
<li><a href="http://www.thegeekstuff.com/2011/10/grep-or-and-not-operators/">Linux Grep OR, Grep AND, Grep NOT Operator Examples</a></li>
<li><a href="https///wodric.com/commande-grep/">Commande grep : Rechercher une aiguille dans un système</a></li>
<li><a href="http://www.codecoffee.com/tipsforlinux/articles/25.html">How to use the most popular command in Unix - Grep </a></li>
<li><a href="http://www.laurent-napias.com/post/2016/02/13/grep-rechercher-de-maniere-recursive-un-terme-ou-plusieurs-dans-tous-les-fichiers-dun-repertoire">Grep, rechercher de manière récursive un terme (ou plusieurs) dans tous les fichiers dun répertoire</a></li>
</ul>
<p>bash_completion est le MOTIF recherché et /usr lendroit où on le recherche (ici dans le dossier /usr). Cest un exemple simple pour voir les différences entre les deux propositions, je vous invite à faire les tests ci-dessous.
grep color=auto -iRnH bash_completion /usr # Proposition chez sois-net.fr</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>-i : Ignorer la casse aussi bien dans le MOTIF (dans notre exemple cest bash_completion) que dans les fichiers
-R : Lire récursivement tous les fichiers à lintérieur de chaque répertoire. Suivre tous les liens symboliques, contrairement à -r
-n : Préfixer chaque ligne de sortie par le numéro de la ligne dans le fichier. La numérotation commence à la ligne 1
-H : Afficher le nom du fichier pour chaque correspondance. Cest le comportement par défaut quand la recherche est effectuée sur plusieurs fichiers (on peut donc sen passer car cest le comportement par défaut et quon utilise loption -R…)
</code></pre></div></div>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>grep --color=auto -RInis 'bash_completion' /usr # Ma proposition
</code></pre></div></div>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>-R : Lire récursivement tous les fichiers à lintérieur de chaque répertoire. Suivre tous les liens symboliques, contrairement à -r
-I : Traiter un fichier binaire comme sil ne contenait aucune correspondance (très utile mais là cest un choix donc à vous de voir, je ne cherche jamais un MOTIF dans un fichier binaire. Avec cette option grep nira pas chercher notre MOTIF dans des fichiers binaires comme /usr/bin/ssh ou /usr/bin/top. Jajoute quun fichier binaire est un fichier qui nest pas un fichier texte par définition)
-n : Préfixer chaque ligne de sortie par le numéro de la ligne dans le fichier. La numérotation commence à la ligne 1
-i : Ignorer la casse aussi bien dans le MOTIF que dans les fichiers
-s : Ne pas afficher les messages derreur concernant les fichiers inexistants ou illisibles (très utile ça évite des messages comme grep: /usr/lib/firefox/hyphenation: Aucun fichier ou dossier de ce type ou encore quand on nest pas root des messages comme grep: /usr/lib/ssl/private: Permission non accordée)
</code></pre></div></div>
<p>Le cas <strong>color=auto</strong> ou <strong>color=always</strong></p>
<p>Avec <strong>color=always</strong> si on chaîne la sortie vers une commande (via un pipe |) ou si on redirige la sortie vers un fichier (via &gt; ou ») alors les caractères liés aux couleurs ne seront pas bien interprétés.</p>
<p>Avec <strong>color=auto</strong>, les couleurs sont affichées sur la sortie sauf si on chaîne la sortie vers une commande ou si on redirige la sortie vers un fichier, on évite ainsi les caractères liés aux couleurs mal interprétés.</p>
<p>A noter que la plupart des utilisateurs voudront utiliser <strong>less</strong> ET avoir la <strong>couleur</strong>, on procèdera donc ainsi :</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>grep --color=always -RInis 'bash_completion' /usr | less -R
</code></pre></div></div>
<h2 id="grep-or-operator">Grep OR Operator</h2>
<p>Use any one of the following 4 methods for <strong>grep OR</strong>. I prefer method number 3 mentioned below for grep OR operator.</p>
<h3 id="1-grep-or-using-">1. Grep OR Using <code class="language-plaintext highlighter-rouge">\|</code>
</h3>
<p>If you use the <code class="language-plaintext highlighter-rouge">grep</code> command without any option, you need to use <code class="language-plaintext highlighter-rouge">\|</code> to separate multiple patterns for the or condition.</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>grep 'pattern1\|pattern2' filename
</code></pre></div></div>
<p>For example, <code class="language-plaintext highlighter-rouge">grep</code> either Tech or Sales from the employee.txt file. Without the back slash in front of the pipe, the following will not work.</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>$ grep 'Tech\|Sales' employee.txt
100 Thomas Manager Sales $5,000
200 Jason Developer Technology $5,500
300 Raj Sysadmin Technology $7,000
500 Randy Manager Sales $6,000
</code></pre></div></div>
<h3 id="2-grep-or-using--e">2. Grep OR Using <code class="language-plaintext highlighter-rouge">-E</code>
</h3>
<p><code class="language-plaintext highlighter-rouge">grep -E</code> option is for extended regexp. If you use the grep command with -E option, you just need to use <code class="language-plaintext highlighter-rouge">|</code> to separate multiple patterns for the or condition.</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>grep -E 'pattern1|pattern2' filename
</code></pre></div></div>
<p>For example, grep either Tech or Sales from the employee.txt file. Just use the <code class="language-plaintext highlighter-rouge">|</code> to separate multiple OR patterns.</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>$ grep -E 'Tech|Sales' employee.txt
100 Thomas Manager Sales $5,000
200 Jason Developer Technology $5,500
300 Raj Sysadmin Technology $7,000
500 Randy Manager Sales $6,000
</code></pre></div></div>
<h3 id="3-grep-or-using-egrep">3. Grep OR Using <code class="language-plaintext highlighter-rouge">egrep</code>
</h3>
<p>egrep is exactly same as <code class="language-plaintext highlighter-rouge">grep -E</code>. So, use egrep (without any option) and separate multiple patterns for the or condition.</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>egrep 'pattern1|pattern2' filename
</code></pre></div></div>
<table>
<tbody>
<tr>
<td>For example, grep either Tech or Sales from the employee.txt file. Just use the</td>
<td>to separate multiple OR patterns.</td>
</tr>
</tbody>
</table>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>$ egrep 'Tech|Sales' employee.txt
100 Thomas Manager Sales $5,000
200 Jason Developer Technology $5,500
300 Raj Sysadmin Technology $7,000
500 Randy Manager Sales $6,000
</code></pre></div></div>
<h3 id="4-grep-or-using-grep--e">4. Grep OR Using <code class="language-plaintext highlighter-rouge">grep -e</code>
</h3>
<p>Using <code class="language-plaintext highlighter-rouge">grep -e</code> option you can pass only one parameter. Use multiple -e option in a single command to use multiple patterns for the or condition.</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>grep -e pattern1 -e pattern2 filename
</code></pre></div></div>
<p>For example, grep either Tech or Sales from the employee.txt file. Use multiple -e option with grep for the multiple OR patterns.</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>$ grep -e Tech -e Sales employee.txt
100 Thomas Manager Sales $5,000
200 Jason Developer Technology $5,500
300 Raj Sysadmin Technology $7,000
500 Randy Manager Sales $6,000
</code></pre></div></div>
<h2 id="grep-and">Grep AND</h2>
<h3 id="1-grep-and-using--e-pattern1pattern2">1. Grep AND using <code class="language-plaintext highlighter-rouge">-E pattern1.*pattern2</code>
</h3>
<p>There is no AND operator in grep. But, you can simulate AND using <code class="language-plaintext highlighter-rouge">grep -E</code> option.</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>grep -E 'pattern1.*pattern2' filename
grep -E 'pattern1.*pattern2|pattern2.*pattern1' filename
</code></pre></div></div>
<p>The following example will grep all the lines that contain both “Dev” and “Tech” in it (in the same order).</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>$ grep -E 'Dev.*Tech' employee.txt
200 Jason Developer Technology $5,500
</code></pre></div></div>
<p>The following example will grep all the lines that contain both “Manager” and “Sales” in it (in any order).</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>$ grep -E 'Manager.*Sales|Sales.*Manager' employee.txt
</code></pre></div></div>
<blockquote>
<p>Note: Using regular expressions in grep is very powerful if you know how to use it effectively.</p>
</blockquote>
<h3 id="2-grep-and-using-multiple-grep-command">2. Grep AND using Multiple grep command</h3>
<p>You can also use multiple grep command separated by pipe to simulate AND scenario.</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>grep -E 'pattern1' filename | grep -E 'pattern2'
</code></pre></div></div>
<p>The following example will grep all the lines that contain both “Manager” and “Sales” in the same line.</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>$ grep Manager employee.txt | grep Sales
100 Thomas Manager Sales $5,000
500 Randy Manager Sales $6,000
</code></pre></div></div>
<h2 id="grep-not">Grep NOT</h2>
<h3 id="1-grep-not-using-grep--v">1. Grep NOT using <code class="language-plaintext highlighter-rouge">grep -v</code>
</h3>
<p>Using <code class="language-plaintext highlighter-rouge">grep -v</code> you can simulate the NOT conditions. -v option is for invert match. i.e It matches all the lines except the given pattern.</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>grep -v 'pattern1' filename
</code></pre></div></div>
<p>For example, display all the lines except those that contains the keyword “Sales”.</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>$ grep -v Sales employee.txt
200 Jason Developer Technology $5,500
300 Raj Sysadmin Technology $7,000
400 Nisha Manager Marketing $9,500
</code></pre></div></div>
<p>You can also combine NOT with other operator to get some powerful combinations.<br>
For example, the following will display either Manager or Developer (bot ignore Sales).</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>$ egrep 'Manager|Developer' employee.txt | grep -v Sales
200 Jason Developer Technology $5,500
400 Nisha Manager Marketing $9,500
</code></pre></div></div>
<h2 id="sed">sed</h2>
<p><a href="https://buzut.net/la-commande-sed-pour-les-nazes/">La commande sed pour les nazes</a></p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sed [OPTION]... {script-only-if-no-other-script} [input-file]...
# Commandes :
sed -e --&gt; commande uniligne
sed -f fichier --&gt; passage de commande par un script
sed -i --&gt; modifie directement le fichier source au lieu de rediriger vers la sortie standard
</code></pre></div></div>
<p>Un champ est défini par une expression rationnelle identifiée par les balises <code class="language-plaintext highlighter-rouge">\(</code> et <code class="language-plaintext highlighter-rouge">\)</code></p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>^ correspond au début d'une ligne (juste avant le premier caractère)
$ correspond à la fin d'une ligne (juste après le dernier caractère)
. correspond à n'importe quel caractère unique
* correspond à aucune ou plusieurs occurrences du caractère qui précède
[ ] correspond à n'importe lequel des caractères cités entre les crochets
&amp; prend la valeur du contenu du fichier avant modif = contenu fichier traité
/./ Récupère toutes les lignes contenant au moins un caractère.
/../ Récupère toutes les lignes contenant au moins deux caractères.
/^#/ Récupère toutes les lignes commençant par un #.
/^$/ Récupère toutes les lignes vides.
/}^/ Récupère toutes les lignes finissant par un }.
/} *^/ Récupère toutes les lignes finissant par un } suivi ou non d'espaces.
/[abc]/ Récupère toutes les lignes contenant un des caractères a, b ou c.
/^[abc]/ Récupère toutes les lignes commençant soit par un a, soit un b, soit un c.
</code></pre></div></div>
<p>Parcourir un fichier et afficher que certaines lignes :</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sed -n '10,12p' passwd
</code></pre></div></div>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>new:x:8:12:news:/etc/news:
ucp:x:13:11:uucp:/var/spool/uucp:/sbin/nologin
operato:x:10:0:operator:/root:/sbin/nologin
</code></pre></div></div>
<p>ici la ligne 10 à 12.</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sed -n '1p'
</code></pre></div></div>
<p>et la juste la première ligne.</p>
<p>Changer un mot par un autre dans vi avec sed :</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>:%s/mot/mot1/g
</code></pre></div></div>
<p>dans le fichier ouvert tous les “mot” seront remplacés par “mot1”</p>
<p>Si on a besoin de remplacer une chaîne par une autre pour toute une liste de fichiers contenu dans un répertoire, on pourra utiliser ce petit script :</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c">#!/bin/bash</span>
<span class="k">for </span>file <span class="k">in</span> <span class="k">*</span>.sh
<span class="k">do
</span><span class="nb">echo</span> “Traitement de <span class="nv">$file</span> …”
<span class="nb">sed</span> <span class="nt">-e</span> “s/chaine1/chaine2/g” “<span class="nv">$file</span><span class="o">&gt;</span><span class="nv">$file</span>”.tmp <span class="o">&amp;&amp;</span> <span class="nb">mv</span> <span class="nt">-f</span><span class="nv">$file</span>”.tmp “<span class="nv">$file</span>
<span class="k">done</span>
</code></pre></div></div>
<p>Ce script va afficher la liste de tous les fichiers dont lextension est .sh et faire le remplacement.</p>
<p>Afficher que les lignes non commentées dun fichier :</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>cat fichier.conf | sed -e '/^#.*$/d'
</code></pre></div></div>
<p>Exemple ou lon remplace le répertoire /root par /home :</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sed -e "s/\/root/\/home/g" fichier &gt; fichier.tmp &amp;&amp; mv -f fichier.tmp fichier
</code></pre></div></div>
<p>Comme vous pouvez le voir vous êtes obligé déchapper les caractères spéciaux.</p>
<p>Remplacer une chaîne par une autre pour une liste de fichiers dans un répertoire, on pourra utiliser ce petit script shell :</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c">#!/bin/bash</span>
<span class="k">for </span>file <span class="k">in</span> <span class="k">*</span>.txt
<span class="k">do
</span><span class="nb">echo</span> <span class="s1">'Traitement de $file ...'</span>
<span class="nb">sed</span> <span class="nt">-e</span> <span class="s1">'s/chaine1/chaine2/g'</span> <span class="s1">'$file'</span> <span class="o">&gt;</span> <span class="s1">'$file'</span>.tmp <span class="o">&amp;&amp;</span> <span class="nb">mv</span> <span class="nt">-f</span> <span class="s1">'$file'</span>.tmp <span class="s1">'$file'</span>
<span class="k">done</span>
</code></pre></div></div>
<p>Mettre tout le contenu dun fichier en majuscule :</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sed -i -e 's/.*/\U&amp;/'
</code></pre></div></div>
<p>Mettre tout le contenu dun fichier en minuscule :</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sed -i -e 's/.*/\L&amp;/'
</code></pre></div></div>
<p>Ajouter un mot ou plus devant chaque ligne dun fichier :</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sed -e 's/.*/mot ou plus &amp;/' appli
</code></pre></div></div>
<p>Ajouter un mot ou plus après chaque ligne dun fichier :</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sed -e 's/.*/&amp; mot ou plus/' appli
</code></pre></div></div>
<p>Ajouter enable à la fin de la ligne comprenant le mot arg1 et arg2 :</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sed -i -e 's/^\(arg1.*arg2\).*$/&amp;1 enable/g' Fichier.txt
</code></pre></div></div>
<p>Afficher la ligne 3 dun fichier :</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sed -n 3p fichier.txt
</code></pre></div></div>
<p>Commenter un ligne contenant le mot httpd :</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sed -i -e 's/.*httpd.*/#$/g' fichier.txt
</code></pre></div></div>
<p>Insérer une nouvelle ligne sous/après une autre :<br>
le fichier contient :</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>lol
ola
mh
pou
</code></pre></div></div>
<p>on insert le mot : client après le mot : ola</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sed -i '/ola/a \client' fichier
</code></pre></div></div>
<p>Suppression dune ligne commençant par le mot : football</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sed -i -e '/^football/d' fichier
</code></pre></div></div>
<p>Autre chose à savoir parce que bien pratique :<br>
Quand vous modifiez des fichiers il est recommandé de créer un fichier de backup au cas ou :</p>
<p>utiliser loption <code class="language-plaintext highlighter-rouge">-i .bak</code></p>
<h2 id="grep---awk---sed">grep - awk - sed</h2>
<h3 id="1-numeroter---compter---additionner---cumuler">1-Numeroter - compter - additionner - cumuler</h3>
<p>Affiche le nombre de lignes (avec les lignes vides)</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -n -e '$=' in.txt
awk 'END{print NR}' in.txt
awk '{n++} END{print n}' in.txt
</code></pre></div></div>
<p>Affiche le nombre de lignes (sans les lignes vides)</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> awk '/./ {print}' in.txt | wc -l
grep "." in.txt | wc -l
</code></pre></div></div>
<p>Somme avec cumul de la colonne 1</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> awk '{print (total +=$1)}' in.txt
</code></pre></div></div>
<p>Print le nombre de mots</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> awk '{x=x+NF}END{print x}' in.txt
</code></pre></div></div>
<p>Compte nombre de lignes contenant le pattern titi</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> awk '/titi/{x+=1}END{print x}' in.txt
</code></pre></div></div>
<p>Print le numero de chaque ligne</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> awk '{print NR,$0}' in.txt
c=0; while read line; do ((c+=1)); echo $c $line; done &lt; in.txt
</code></pre></div></div>
<p>compteur vertical</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> for i in `seq 1 15`;do echo "$i";done
</code></pre></div></div>
<p>Compte le nombre de lignes vides dun fichier</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> awk '/^$/ {x += 1};END {print x }' in.txt
</code></pre></div></div>
<p>Compter le nombre de mots dun fichier</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> cat in.txt | wc -w
</code></pre></div></div>
<p>compter le nombre de lignes et de mots</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> awk 'BEGIN{nl=0;nw=0} {nl++;nw+=NF} END {print "lines:",nl, "words:",nw}' in.txt
</code></pre></div></div>
<p>compter un caractere (ici: i)</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> var=`cat in.txt` ; var="${var//[^i]/}" ; echo ${#var}
</code></pre></div></div>
<p>affiche le numero de ligne du pattern</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> grep -n "pattern" in.txt
</code></pre></div></div>
<p>Compter le nombre doccurrences de pattern</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> grep -c "pattern" in.txt
awk '/pattern/ {n++} END {print n}' in.txt
</code></pre></div></div>
<p>Numeroter toutes les lignes contenant pattern (affiche 1 numero par ligne)</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -n '/pattern/=' in.txt
</code></pre></div></div>
<p>Numeroter toutes les lignes entre 2 patterns (affiche 1 numero par ligne)</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -n '/pattern1/,/pattern2/{=;d;}' in.txt
</code></pre></div></div>
<p>Numeroter les lignes sans les lignes blanches</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> nl in.txt
</code></pre></div></div>
<p>Numeroter les lignes avec les lignes blanches</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> cat -n in.txt
sed = in.txt | sed 'N; s/\n/\t/'
</code></pre></div></div>
<p>Numeroter les lignes</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> awk '{print NR,$0}' in.txt
while read line; do N=$((N+1)); echo "Line $N = $line"; done &lt; in.txt
</code></pre></div></div>
<p>Ecrire le nom du fichier devant chaque ligne</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> grep -H "pattern" in.txt
</code></pre></div></div>
<p>Somme et cumul dune colonne ($2) , en utilisant 1 colonne clef ($1)</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> awk '{arr[$1]+=$2} END {for(i in arr) {print i, arr[i]}}' in.txt | sort
</code></pre></div></div>
<h3 id="2-operations-sur-les-champs--nf">2-Operations sur les champs : NF</h3>
<p>Compter le nombre de champs de chaque ligne (separateur = “,”)</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> awk '{cnt=0 ; for(i=1; i&lt;=NF; i++) {if($i != "") {cnt++}} {print NR " : "cnt" fields"}}' FS="," in.txt
</code></pre></div></div>
<p>Printer les 5 premiers caractères de toutes les lignes dun fichier</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> while read line;do echo ${line::5};done &lt; in.txt
while read line ; do echo $line | cut -c1-5 ; done &lt; in.txt
</code></pre></div></div>
<p>Deleter les 5 premiers caracteres de toutes les lignes dun fichier</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> colrm 1 5 &lt; in.txt
awk 'sub("^.....", "")' in.txt
while read line ; do echo $line | cut -c6- ; done &lt; in.txt
</code></pre></div></div>
<p>Printer les 5 derniers caracteres de toutes les lignes</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed 's/^.*\(.....\)$/\1/' in.txt
sed 's/\(.*\)\(.\{5\}\)/\2/' in.txt
while read line;do echo ${line: -5};done &lt; in.txt
awk '{print substr($0, length($0) - 4, length($0) ) }' in.txt
</code></pre></div></div>
<p>Deleter les 5 derniers caracteres de toutes les lignes</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> awk 'sub(".....$", "")' in.txt
</code></pre></div></div>
<p>Supprimer un champ</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> echo "data1 line1" | sed 's/.* //'
echo "data1 line1" | sed -n 's/.* //;p'
resultat: line1
</code></pre></div></div>
<p>Supprimer le dernier champ</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> awk '{$NF=""; print $0}' in.txt
</code></pre></div></div>
<p>Champ tampon elapse pour operations intermediaires</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> awk '{elapse = $1/3600; if(elapse&lt;8) print int($1/3600)}' in.txt
</code></pre></div></div>
<p>Dans champ 1, a la position 2, printer 3 caracteres</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> awk '{print substr($1,2,3)}' in.txt
</code></pre></div></div>
<p>Print lavant dernier champ ($NF-1) de chaque ligne</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> awk '{print $(NF-1)}' in.txt
</code></pre></div></div>
<p>Print le nombre de champs uniquement</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> awk '{print NF}' in.txt
</code></pre></div></div>
<p>Print le nombre maximum de champs</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> awk '{print NF}' in.txt | sort -n | sed -n '$p'
</code></pre></div></div>
<p>Print le nombre minimum de champs</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> awk '{print NF}' in.txt | sort -n | sed -n '1p'
</code></pre></div></div>
<p>Printer 2 colonnes en precisant le separateur</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> awk -F'[ ]' '{print $2,$3}' in.txt
cut -d ' ' -f2,3 in.txt
</code></pre></div></div>
<p>Printer du 5eme caractere au dernier (inclus) sur toutes les lignes dun fichier</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> cat in.txt | cut -c '5-'
</code></pre></div></div>
<p>Printer du 1er au 5eme caractere (inclus) sur toutes les lignes dun fichier</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> cat in.txt | cut -c '-5'
</code></pre></div></div>
<p>Printer du 3eme au 5eme caractere (inclus) et du 7eme au 9eme (inclus) sur toutes les lignes dun fichier</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> cat in.txt | cut -c '3-5,7-9'
</code></pre></div></div>
<p>Printer les lignes dont le nombre de champs est inferieur a 3</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> awk 'NF&lt;3' in.txt
</code></pre></div></div>
<p>Printer les lignes nayant quun seul champ</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> awk '{if(NF == 1) {print}}' in.txt
</code></pre></div></div>
<p>tri de la 1ère colonne au 22eme caractere</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sort -k1.22
</code></pre></div></div>
<p>Print si longueur de colonne 1 &gt;3 “ET” ou “OU” longueur de colonne 2 &lt;5</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> awk 'length($1)&gt;3 &amp;&amp; length($2)&lt;5 {print}' in.txt ........... #ET
awk 'length($1)&gt;3 || length($2)&lt;5 {print}' in.txt ........... #OU
</code></pre></div></div>
<p>Condition de print sur la longueur de colonne</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> awk '{if(length($1)&lt;2 &amp;&amp; $1~/2/) {print $2} else {print $1}}' in.txt
</code></pre></div></div>
<h3 id="3-operations-sur-les-lignes--occurrences---digits---suppression---doubles---printer">3-operations sur les lignes : occurrences - digits - suppression - doubles - printer</h3>
<p>Capturer la premiere occurrence dune serie de lignes ayant meme pattern</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> cat in.txt | sort -k1 | awk 'x !~ $1 ; {x = $1}'
cat in.txt | sort -k1 | awk '!d[$1] {print} {d[$1]=1}'
cat in.txt | sort -k1 | awk 'x[$1]++ {next} {print}'
cat in.txt | sort -k1 | awk '!_[$1]++ {print $0 ; next} {next}'
</code></pre></div></div>
<p>Compter et marquer a la fin de la ligne les occurrences dun unique pattern</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> awk '/pattern/ {i=i+1} {print $0,i}' in.txt | awk '!a[NF]++ {print $0 ; next} {sub($NF,"") ; print}'
</code></pre></div></div>
<p>Compter les occurrences dun pattern (total cumule)</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> awk '/pattern/ {n++} END {print "pattern ecrit" n "fois"}' in.txt
</code></pre></div></div>
<p>Compter les occurrences dun pattern (pour chaque ligne)</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> awk -F "pattern" '{print NF-1}' in.txt
</code></pre></div></div>
<p>Remplace sur chaque ligne la 1ère occurrence de t par b</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -e '1,$ s/t/b/1' in.txt
while read line; do echo ${line/t/b}; done &lt; in.txt
</code></pre></div></div>
<p>Remplacer la 2ème occurrence dun pattern de la premiere ligne</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed '0,/old/ s//new/2' in.txt
</code></pre></div></div>
<p>Remplacer la 2ème occurrence dun pattern pour chaque ligne</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed 's/old/new/2' in.txt
sed '/old/ s//new/2' in.txt
awk '{print gensub(/old/, "new", 2)}' in.txt
</code></pre></div></div>
<p>Print la 1ère occurrence dun “pattern”</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> grep -m1 "pattern" in.txt
sed -n '/pattern/{p;q;}' in.txt
</code></pre></div></div>
<p>Printer les lignes dont les elements de la colonne 2 ont plus dune occurrence</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> awk 'FNR==NR &amp;&amp; a[$2]++ {b[$2] ; next} $2 in b' in.txt in.txt
</code></pre></div></div>
<p>Printer les 4 premiers digits de chaque ligne</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> cat in.txt | cut -c1-4
for line in $(cat in.txt); do echo `expr "$line" : '\(....\)'`; done
while read line; do echo `expr "$line" : '\(....\)'`; done &lt; in.txt
</code></pre></div></div>
<p>Printer les 4 derniers digits de chaque ligne</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> awk '{print substr($0, length($0)-3, length($0))}' in.txt
</code></pre></div></div>
<p>Deleter les 3 derniers digits de chaque ligne</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -n '1,$ s/...$//p' in.txt
</code></pre></div></div>
<p>Printer du 5ème digit au dernier de la ligne pour toutes les lignes</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> while read line; do echo "substr($line,4)" | m4; done &lt; in.txt
</code></pre></div></div>
<p>Printer 6 digits à partir du 2ème digit</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> while read line; do echo `expr substr "$line" 2 6`; done &lt; in.txt
</code></pre></div></div>
<p>Supprime de la ligne 4 a 7 (inclus) du fichier</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed '4,7d' in.txt
</code></pre></div></div>
<p>Supprime les lignes contenant toto</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed '/toto/d' in.txt
grep -v "toto" in.txt
</code></pre></div></div>
<p>Supprime toto de la ligne 2 a 6</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -e '2,6 s/toto//g' in.txt
</code></pre></div></div>
<p>Supprime les lignes debutant par un chiffre (1 a 9)</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> awk '$1 ~ /^[1-9]/ {next} {print}' in.txt
</code></pre></div></div>
<p>Supprime la ligne debutant par @ et les 2 suivantes</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed '/^@/ {N;N;d;}' in.txt
</code></pre></div></div>
<p>Supprimer la 1ere ligne , la derniere ligne …</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed '1d' in.txt ........... #supprime la premiere ligne
sed '3d' in.txt ........... #supprime la ligne 3
sed '$d' in.txt ........... #supprime la derniere ligne
</code></pre></div></div>
<p>Supprimer les lignes 1, 4, 7, 10…..</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -e '1~3d' in.txt
</code></pre></div></div>
<p>Supprimer 1 ligne toutes les 3 lignes</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed '0~3d' in.txt
sed 'n;n;d;' in.txt
</code></pre></div></div>
<p>Deleter les 2 dernieres lignes</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed 'N;$!P;$!D;$d' in.txt
</code></pre></div></div>
<p>Deleter les 10 dernieres lignes</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -e :a -e '$d;N;2,10ba' -e 'P;D'
sed -n -e :a -e '1,10!{P;N;D;};N;ba'
</code></pre></div></div>
<p>Printer les lignes uniques sans les doubles</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sort -u in.txt
sort in.txt | uniq
awk '!x[$0]++' in.txt
awk '{ a[$1]++ } END {for (i in a) print i}' in.txt | sort
sed '$!N; /^\(.*\)\n\1$/!P; D' in.txt .........consecutive lines
</code></pre></div></div>
<p>Printer les lignes doubles , deleter le reste</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> awk 'x[$0]++' in.txt
cat in.txt | uniq -d
sed '$!N; s/^\(.*\)\n\1$/\1/; t; D' in.txt
</code></pre></div></div>
<p>Printer les lignes doubles (ou triples …)</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> awk 'FNR==NR &amp;&amp; a[$0]++ {b[$0] ; next} $0 in b' in.txt in.txt
</code></pre></div></div>
<p>Printer uniquement la ligne 10</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed '10q;d' in.txt
sed '10!d' in.txt
sed -n '10p' in.txt
awk '{f[NR]=$0} END {print f[10]}' in.txt
awk 'NR == 10 {print}' in.txt
</code></pre></div></div>
<p>Printer de la ligne 1 a 10</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed 10q in.txt
awk 'NR &lt;=10{print}' in.txt
</code></pre></div></div>
<p>Printer de la ligne 3 a 5</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed '3,5!d' in.txt
sed -n '3,5p' in.txt
awk 'NR &gt;= 3 &amp;&amp; NR &lt;= 5' in.txt
head -5 in.txt | tail -3
sed -n '3{:a;N;5!ba;p}' in.txt
</code></pre></div></div>
<p>Printer la ligne 5 et 10 dune serie de fichiers</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> for i in fichiers*;do awk 'NR == 5;NR == 10 {print $0}' $i;done
</code></pre></div></div>
<p>Printer de la ligne 5 a 10 en numerotant</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> awk 'NR == 5,NR == 10 {print NR" " $0}' in.txt
</code></pre></div></div>
<p>Printer la 1ere ligne à la place de la 3eme ligne</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -n -e '1h; 1!p; 3{g;p}' in.txt
</code></pre></div></div>
<p>Printer la 1ere ligne</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed q in.txt
</code></pre></div></div>
<p>Printer la dernière ligne</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -n '$p' in.txt
sed '$!d' in.txt
</code></pre></div></div>
<p>Printer les 2 dernieres lignes</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed '$!N;$!D' in.txt
</code></pre></div></div>
<p>Printer les 10 dernieres lignes</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -e :a -e '$q;N;11,$D;ba' in.txt
</code></pre></div></div>
<p>Printer la 1ere et derniere ligne</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> head -1 in.txt ; tail -1 in.txt
sed -n '1p ; $p' in.txt
awk 'NR==1 ; END {print}' in.txt
sed q in.txt;sed '$!d' in.txt
sed q in.txt;sed '$\!d' in.txt ..........#selon version de Linux
IFS=$'\n';array=($(cat in.txt)); echo ${array[0]};sed '$!d' in.txt ........#en sous shell
</code></pre></div></div>
<p>Printer les lignes ayant moins de 6 caracteres</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed '/^.\{6,\}/d' in.txt
</code></pre></div></div>
<p>Printer les lignes de 6 caracteres ou plus</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -n '/^.\{6\}/p' in.txt
</code></pre></div></div>
<p>Indexage du premier t lu pour chaque ligne</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> while read line; do echo `expr index "$line" t`; done &lt; in.txt
</code></pre></div></div>
<p>Longueur de chaque ligne (en nombre de digits) - voir si la version de Linux supporte : m4 </p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> while read line; do echo "len($line)" | m4; done &lt; in.txt
while read line; do echo `expr length "$line"`; done &lt; in.txt
</code></pre></div></div>
<p>Formater sur une meme ligne : une ligne paire a droite dune ligne impaire</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> cat in.txt | sed "N;s/\(.*\)\n\(.*\)/\1 \2/"
cat in.txt | sed "N;s/\n/ /"
cat in.txt | sed '$ !N; s/\n/ /'
</code></pre></div></div>
<p>Formater sur une meme ligne : une ligne impaire a droite dune ligne paire</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> cat in.txt | sed "N;s/\(.*\)\n\(.*\)/\2 \1/"
</code></pre></div></div>
<p>Affiche 1 ligne sur 2 (lignes 1, 3, 5…)</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed 'n;d' in.txt
sed -n 'p;n' in.txt
sed -n '1,${p;n;}' in.txt
sed '2~2d' in.txt
awk 'FNR % 2' in.txt
awk 'NR%2 {print}' in.txt
awk 'NR%2 == 1' in.txt
</code></pre></div></div>
<p>Affiche 1 ligne sur 2 (lignes 2, 4, 6…)</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -n 'n;p' in.txt
sed -n '1,${n;p;}' in.txt
sed '1~2d' in.txt
awk '!(FNR % 2)' in.txt
awk '(NR+1)%2 {print}' in.txt
awk 'NR%2 == 0' in.txt
</code></pre></div></div>
<p>Affiche 1 ligne sur 5 a partir de la ligne 3</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -n '3,${p;n;n;n;n;}' in.txt
</code></pre></div></div>
<p>Recherche de la ligne la plus longue</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> awk '{ if ( length &gt; L ) { L=length ; s=$0 } } END { print L,"\""s"\""}' in.txt
</code></pre></div></div>
<h3 id="4-pattern">4-pattern</h3>
<p>Capture dun pattern dans 1 fichier</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> grep 'pattern' in.txt
grep -w 'pattern' in.txt
awk '/pattern/' in.txt
awk '$0 ~ /\ypattern\y/ {print}' in.txt
sed -n '/pattern/p' in.txt
sed '/pattern/ !d' in.txt
grep '\&lt;pattern\&gt;' in.txt
</code></pre></div></div>
<p>Printer les lignes ne contenant que des chiffres</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -n '/^[[:digit:]]*$/p' in.txt
</code></pre></div></div>
<p>Printer les lignes ne contenant que des lettres</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -n '/^[[:alpha:]]*$/p' in.txt
</code></pre></div></div>
<p>Capture dun pattern dans plusieurs fichiers</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> grep "pattern" in*.txt
for i in in*.txt;do seq=`ls $i`;awk '/pattern/ {print seq,$0}' seq=${seq} $i;done
</code></pre></div></div>
<p>Printer un paragraphe separe par des lignes blanches , contenant un pattern</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -e '/./{H;$!d;}' -e 'x;/pattern/!d;' in.txt
</code></pre></div></div>
<p>Printer un paragraphe separe par des lignes blanches , contenant pattern1 et pattern2</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -e '/./{H;$!d;}' -e 'x;/pattern1/!d;/pattern2/!d' in.txt
</code></pre></div></div>
<p>Printer un paragraphe separe par des lignes blanches , contenant pattern1 ou pattern2</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -e '/./{H;$!d;}' -e 'x;/pattern1/b' -e '/pattern2/b' -e d in.txt
</code></pre></div></div>
<p>Capturer dans la colonne 1 le pattern 2 et printer la colonne 3</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> awk '$1 ~ /2/ {print $3}' in.txt
awk '$1 == "2" {print $3}' in.txt
awk '{if($1 ~ /t/){gsub(/t/, "z",$1);print $0}}' in.txt
awk '$1 !~ /2/ {print $3}' in.txt ........... #syntaxe inverse
awk '$1 \!~ /2/ {print $3}' in.txt ...........#syntaxe inverse (selon version Linux)
</code></pre></div></div>
<p>Supprimer les lignes contenant des patterns</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> awk '$1 !~ /pattern1/ &amp;&amp; $2 !~ /pattern2/ ' in.txt
awk '$1 ~ /pattern1/ || $2 ~ /pattern2/ {next} {print}' in.txt
</code></pre></div></div>
<p>Capturer le caractère # à la 4ème position</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> egrep '^.{3}#' in.txt
</code></pre></div></div>
<p>Capturer les lignes commencant par 1 espace ou plus, sans celles commencant par 2 espaces</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> grep "[ ]\{1\}" in.txt | awk '$0 !~ /^ / {print}'
</code></pre></div></div>
<p>Capturer les lignes ayant 4 chiffres ou plus</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> grep "[0-9]\{4\}" in.txt
</code></pre></div></div>
<p>Lire plusieurs patterns - (possibilite de lignes doubles)</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> awk '/pattern1/ {print $0} /pattern2/ {print $0}' in.txt
awk 'FNR==NR &amp;&amp; a[$0]=/^t/ || a[$0]=/^d/ {b[$0] ; next} $0 in b' in.txt in.txt
</code></pre></div></div>
<p>utiliser egrep si le pattern a plusieurs lignes</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> egrep -a "MIN WORD 2|MIN WORD32" in.txt
</code></pre></div></div>
<p>ajouter antislash <code class="language-plaintext highlighter-rouge">\</code> pour le caractère special: <code class="language-plaintext highlighter-rouge">|</code></p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> egrep "3 \|DISK|4 \| DISK" in.txt
</code></pre></div></div>
<p>pattern1 OR pattern2</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed '/[pattern1pattern2]/!d' in.txt
sed -e '/pattern1/b' -e '/pattern2/b' -e d in.txt
awk '/pattern1|pattern2/' in.txt
grep -E "pattern1|pattern2" in.txt
grep -e pattern1 -e pattern2 in.txt
</code></pre></div></div>
<p>pattern1 AND pattern2</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed '/a/!d; /b/!d' in.txt
sed '/pattern1.*pattern2/!d in.txt
awk '/pattern1.*pattern2/' in.txt
awk '/pattern1/ &amp;&amp; /pattern2/' in.txt
grep -E 'pattern1.*pattern2' in.txt
</code></pre></div></div>
<p>NOT pattern1</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> grep -v 'pattern1' in .txt
awk '!/pattern1/' in.txt
sed -n '/pattern1/!p' in.txt
</code></pre></div></div>
<p>Printer les 2 premieres occurrences du pattern</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> grep -m2 "tata" in.txt
</code></pre></div></div>
<p>Substitution uniquement pour la 1ere occurrence</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed '0,/tata/ s//zaza/' in.txt
</code></pre></div></div>
<p>Remplace old par new uniquement sur les lignes commencant par %%</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed '/^%%/ s/old/new/g' in.txt
</code></pre></div></div>
<p>Remplace sur chaque ligne du début de la ligne au signe = par new</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -e '1,$ s/^.*=/new/' in.txt
</code></pre></div></div>
<p>Supprimer la ligne contenant toto entre titi et tutu</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -e '/titi/,/tutu/ {/toto/d}' in.txt
</code></pre></div></div>
<p>Capture entre toto et tata (attention si plusieurs occurrences du pattern)</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -n '/toto/,/tata/p' in.txt
sed -e '/toto/,/tata/ !{/./d}' in.txt
sed -e '/toto/,/tata/ \!{/./d}' in.txt
perl -e "while(&lt;&gt;) {print if/toto/.../tata/}" in.txt
awk "/toto/,/tata/" in.txt
</code></pre></div></div>
<p>Supprimer entre pattern1 et pattern2 (les patterns inclus)</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -e '/pattern1/,/pattern2/d' in.txt
</code></pre></div></div>
<p>Supprimer dun debut de fichier a un pattern</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -e '1,/pattern/d' in.txt
</code></pre></div></div>
<p>Supprimer dun pattern a la fin dun fichier</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -e '/pattern/,$d' in.txt
</code></pre></div></div>
<p>Substitution entre 2 patterns</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed '/titi/,/tata/ s/toto/zz/g' in.txt
</code></pre></div></div>
<p>Definir un pattern sur lequel la substitution ne se fera pas</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed '/toto/!s/t/z/g' in.txt
</code></pre></div></div>
<p>Printer entre titi et tutu</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -n '/titi/{:a;N;/tutu/!ba;p;}' in.txt
</code></pre></div></div>
<p>Capture de titi a tutu de la ligne 3 a 10</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -n '3,10{/titi/,/tutu/p}' in.txt
</code></pre></div></div>
<p>Supprimer une ligne contenant un pattern + les 2 lignes suivantes</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed '/pattern/,+2d' in.txt
</code></pre></div></div>
<p>Supprimer de la ligne 3 a la ligne contenant pattern</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -e '3,/pattern/d' in.txt
</code></pre></div></div>
<p>Printer dune ligne contenant 1 pattern jusqua la fin</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -n '/pattern/,$p' in.txt
sed -n '/pattern/,EOF' in.txt
</code></pre></div></div>
<p>Si le pattern est une variable</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -n '/'$var'/p' in.txt
</code></pre></div></div>
<p>Ne pas selectionner les lignes contenant un pattern</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> grep -v "pattern" in.txt
awk '!/pattern/' in.txt
sed '/pattern/d' in.txt
sed -n '/pattern/!p' in.txt
awk '$0 ~ /pattern/ {next} {print}' in.txt
</code></pre></div></div>
<p>A un pattern inserer une ligne</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -e '/pattern/ i\ligne ecrite avant le pattern' in.txt ............ (option 'i' : avant le pattern)
sed -e '/pattern/ a\ligne ecrite apres le pattern' in.txt ............ (option 'a' : apres le pattern)
</code></pre></div></div>
<p>A un pattern inserer une ligne blanche</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -e '/pattern/ i\ ' in.txt ............ (option 'i' : avant le pattern)
sed -e '/pattern/ a\ ' in.txt ............ (option 'a' : apres le pattern)
</code></pre></div></div>
<p>print 2 lignes après un pattern ( dans la colonne 1 )</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> awk '/^pattern/ {c=2; next} c--&gt;0' in.txt
awk 'BEGIN {counter=0}; $1=="pattern" {counter=2; next}; counter&gt;0 {counter--; print}' in.txt
</code></pre></div></div>
<p>print le pattern + 2 lignes après (After)</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> grep -A2 "pattern" in.txt
sed -n '/pattern/ {N;N;p;}' in.txt
</code></pre></div></div>
<p>delete le pattern + 2 lignes après</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed '/pattern/ {N;N;d;}' in.txt
</code></pre></div></div>
<p>print le pattern + 2 lignes avant (Before)</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> grep -B2 "pattern" in.txt
</code></pre></div></div>
<p>selectionner tous les caracteres (sans afficher les lignes blanches)</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> grep "." in.txt
awk "/./" in.txt
sed -n '/./ {p;d}' in.txt
</code></pre></div></div>
<p>combiner motif et ligne</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed '8,/fin/ s/toto/titi/g' in.txt
sed '/debut/,$ s/toto/titi/g' in.txt
</code></pre></div></div>
<p>substituer tout un texte entre 2 motifs excluant les motifs</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed '/titi/,/tutu/{/titi/b;/tutu/b;s/.*/SED/;}' in.txt
</code></pre></div></div>
<p>ne pas printer les lignes contenant tata</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed '/tata/d' in.txt
sed -n '/tata/!p' in.txt
</code></pre></div></div>
<p>Printer les lignes precedant un pattern</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -n '/tata/{g;1!p;};h' in.txt
</code></pre></div></div>
<p>Printer les lignes suivant un pattern</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -n '/tata/{n;p;}' in.txt
</code></pre></div></div>
<p>Remembering a pattern (_ is delimiter)</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> echo "a line1" | sed 's_\([a-z]\)\([ ]\)\([a-z]*\)\([0-9]\)_\1\2\3 \4_'
(result: a line 1)
</code></pre></div></div>
<h3 id="5-remplacer-des-lignes-des-chiffres-ou-des-lettres">5-Remplacer des lignes des chiffres ou des lettres</h3>
<p>Exemple dune suite dactions entre 2 patterns</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -n '4,10 {/pattern1/,/pattern2/ {s/^0./y&amp;/;/^$/d;s/m/w/g;p}}' in.txt
</code></pre></div></div>
<p>Supprimer tous les chiffres en gardant un tiret - a la place</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> tr -d 0-9 &lt; in.txt
</code></pre></div></div>
<p>supprimer toutes les lettres en gardant un tiret - a la place</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> tr -d [a-zA-Z] &lt; in.txt
</code></pre></div></div>
<p>Conserver les lignes contenant des chiffres</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -e '/[0-9]/!d' in.txt
sed -e '/[0-9]/\!d' in.txt ........... (selon version Unix)
</code></pre></div></div>
<p>Changer un texte majuscule en minuscule</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> awk '{print tolower($0)}' in.txt
cat in.txt | tr -s A-Z a-z
</code></pre></div></div>
<p>Changer un texte minuscule en majuscule</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> cat in.txt | tr -s a-z A-Z
</code></pre></div></div>
<p>Supprimer les lettres minuscules en fin de ligne</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> awk '{ sub("[a-z]*$", ""); print }' in.txt
</code></pre></div></div>
<p>print le pattern sans distinguer majuscules ou minuscules</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> grep -i "pattern" in.txt
</code></pre></div></div>
<p>Mettre en majuscule la 1ère lettre dune phrase</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> echo -e "texte ligne1\ntexte ligne2" | sed 's/^./\u&amp;/'
</code></pre></div></div>
<p>Remplacer les lettres par une operande (ici: +)</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> cat in.txt | tr '[:alpha:]' +
</code></pre></div></div>
<p>Remplacer les chiffres par une operande (ici: +)</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> cat in.txt | tr '[:digit:]' +
</code></pre></div></div>
<p>Remplacer 1 caractere par un autre</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> tr "t" "z" &lt; in.txt
</code></pre></div></div>
<p>Suppression des sauts de lignes</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> tr '\n' ' ' &lt; in.txt
</code></pre></div></div>
<p>Supprimer la répétition de caractères</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> echo "boonnjoouuur" | tr -s "onu"
</code></pre></div></div>
<p>Remplace le bloc (t suivi de 2 caracteres) par zorro en ligne 4</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -e '4s/t../zorro/g' in.txt
</code></pre></div></div>
<p>Inserer 1 caractere (1 point=1 caractere)</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> ( ici l'insertion de 'Q' se fera apres les 2 premiers caractères )
echo 'abcdef' | sed 's/^../&amp;Q/' ........... #resultat : abQcdef
</code></pre></div></div>
<p>Remplacer en debut de chaine un nombre de points par une lettre</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> echo 'abcdef' | sed 's/^../Q/' ........... #resultat : Qcdef
</code></pre></div></div>
<p>Uniquement le 2eme caractere t est remplace par z en ligne 4</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -e '4s/t/z/2' in.txt
awk 'NR==4 {print gensub(/t/,"z",2)}; NR!=4 {print}' in.txt
</code></pre></div></div>
<p>Remplace t par k , et o par l</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed 'y/to/kl/' in.txt
</code></pre></div></div>
<p>Effectue le remplacement des lignes 4 a 10 et necrit dans out.txt que celles modifiees</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -e '4,10 s/t/&amp;zorro/gw out.txt' in.txt
</code></pre></div></div>
<p>Remplacer un pattern (titi remplace par: titi et tata)</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed '/titi/ s//&amp; et tata/g' in.txt
sed 's/titi/titi et tata/g' in.txt
</code></pre></div></div>
<p>tr : remplacement dans un sous shell (taper: sh)</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> a=abcdef; echo $a | tr f g ........... #resultat : abcdeg
a=abcdef; echo ${a//f/g} ........... #resultat : abcdeg
a=abcdef; echo $a | tr [ac] [xz] ........... #resultat : xbzdef
</code></pre></div></div>
<p>tr + option -d: effacement (utiliser un sous shell) (taper: sh)</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> a=abcdef; echo $a | tr -d f ........... #resultat : abcde
a=abcdef; echo ${a//f/} ........... #resultat : abcde
a=abcdef; echo $a | tr -d [a-c] ........... #resultat : def
a=abcdef; echo ${a//[a-c]/} ........... #resultat : def
a=abcdef; echo $a | tr -d [ac] ........... #resultat : bdef
a=abcdef; echo ${a//[ac]/} ........... #resultat : bdef
</code></pre></div></div>
<p>tr + option -c: inverse lensemble des caractères a detecter</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> echo "acfdeb123" | tr -c b-d + ....... resultat: +c+d+b++++
</code></pre></div></div>
<p>Remplacer toutes les occurrences dun caractère ou dun pattern pour chaque ligne</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> var="newpattern" ; awk '{gsub( /oldpattern/, "'"$var"'" )};1' in.txt
var="newpattern" ; awk -v v="$var" '{gsub( /oldpattern/, v )}1' in.txt
</code></pre></div></div>
<p>Remplacer la 2eme occurrence dun caractère ou dun pattern pour chaque ligne</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> awk '{print gensub(/old/, "new", 2) }' in.txt
</code></pre></div></div>
<p>Remplacer o par zorro sauf pour le pattern toto ,</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -e '/toto/!s/o/zorro/' in.txt
</code></pre></div></div>
<p>Supprimer les 3 derniers caractères de la dernière ligne uniquement</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> expr "$(cat in.txt)" : "\(.*\)...$"
</code></pre></div></div>
<p>Supprimer les 3 derniers caractères de chaque ligne</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> awk 'sub( "...$", "" )' in.txt
</code></pre></div></div>
<p>Printer les 5 premiers caractères de la premiere ligne</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> echo `cat in.txt`| cut -c1-5
echo `expr "$(cat in.txt)" : '\(.....\)'`
</code></pre></div></div>
<p>Printer les 5 premiers caractères de toutes les lignes dun fichier</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> cat in.txt | cut -c1-5
while read line;do echo ${line::5};done &lt; in.txt
while read line ; do echo $line | cut -c1-5 ; done &lt; in.txt
</code></pre></div></div>
<p>Printer les 5 derniers caracteres de toutes les lignes dun fichier</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> while read line;do echo ${line: -5};done &lt; in.txt
sed 's/^.*\(.....\)$/\1/' in.txt
sed 's/\(.*\)\(.\{5\}\)/\2/' in.txt
</code></pre></div></div>
<p>Substituer toto ou titi par tata</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed 's/toto\|titi/tata/g' in.txt
</code></pre></div></div>
<h3 id="6-supprimer-des-lignes-blanches-espaces-tabulations-contenu-entre-2-balises-balises-incluses">6-Supprimer des lignes blanches ,espaces ,tabulations, contenu entre 2 balises (balises incluses)</h3>
<p>Supprimer contenu entre 2 balises (balises incluses)<br>
Exemple ,supprimer le contenu entre <code class="language-plaintext highlighter-rouge">&lt;ele&gt;</code> et <code class="language-plaintext highlighter-rouge">&lt;/time&gt;</code> dun fichier nommé test.gpx</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>&lt;trkpt lat="47.0134660788" lon="-1.1192788649"&gt;&lt;ele&gt;50.61&lt;/ele&gt;&lt;time&gt;2020-07-07T04:24:19Z&lt;/time&gt;&lt;/trkpt&gt;
&lt;trkpt lat="47.0134599600" lon="-1.1192838103"&gt;&lt;ele&gt;50.13&lt;/ele&gt;&lt;time&gt;2020-07-07T04:24:42Z&lt;/time&gt;&lt;/trkpt&gt;
&lt;trkpt lat="47.0134515781" lon="-1.1192932818"&gt;&lt;ele&gt;49.65&lt;/ele&gt;&lt;time&gt;2020-07-07T04:25:01Z&lt;/time&gt;&lt;/trkpt&gt;
</code></pre></div></div>
<p>La commande</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sed "s/&lt;ele&gt;.*&lt;\/time&gt;//" test.gpx # sed -i pour récréer le fichier
</code></pre></div></div>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>&lt;trkpt lat="47.0134660788" lon="-1.1192788649"&gt;&lt;/trkpt&gt;
&lt;trkpt lat="47.0134599600" lon="-1.1192838103"&gt;&lt;/trkpt&gt;
&lt;trkpt lat="47.0134515781" lon="-1.1192932818"&gt;&lt;/trkpt&gt;
</code></pre></div></div>
<p>Supprimer les lignes blanches (loption -i reecrit directement dans le fichier)</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed '/./!d' in.txt
sed -i '/^$/d' in.txt ........... (l'option '-i' est a manier avec precaution)
</code></pre></div></div>
<p>Supprimer les lignes blanches repetees sauf la 1ere</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> cat -s in.txt
</code></pre></div></div>
<p>Supprimer uniquement les lignes blanches du debut du fichier</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed '/./,$!d' in.txt
</code></pre></div></div>
<p>Supprimer tout ce qui suit la 1ere ligne blanche</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed '/^$/q' in.txt
</code></pre></div></div>
<p>Supprimer tout ce qui precede la 1ere ligne blanche</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed '1,/^$/d' in.txt
</code></pre></div></div>
<p>Supprimer les lignes blanches entre tata et route</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -e '/tata/,/route/ {/^$/d}' in.txt
</code></pre></div></div>
<p>Remplacer 2 blancs (ou +) par 1 seul blanc</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed 's/\ \ */\ /g' in.txt
</code></pre></div></div>
<p>Suppression des espaces et tabulations en debut et fin de ligne</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed 's/^[ \t]*//;s/[ \t]*$//' in.txt
</code></pre></div></div>
<p>Suppression des lignes vides</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> grep -v '^$' in.txt
grep '.' in.txt
sed -n '/^$/!p' in.txt
awk NF in.txt
awk '/./' in.txt
sed '/^$/d' in.txt
sed '/./!d' in.txt
awk '/^$/ {next} {print}' in.txt
</code></pre></div></div>
<p>tr + option squeeze-repeats: efface tout sauf la première</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> occurence d'une chaîne de caractères
(utile pour supprimer plusieurs espaces blancs)
echo "XXXXX" | tr --squeeze-repeats 'X' ....... resultat: X
</code></pre></div></div>
<p>Supprime tous les espaces au début de toutes les lignes</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed 's/^ *//g' in.txt
</code></pre></div></div>
<p>Supprime tous les espaces à la fin de toutes les lignes</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed 's/ *$//g' in.txt
</code></pre></div></div>
<p>Supprimer seulement la première ligne de chaque ensemble de lignes vides consecutives</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed '/[0-9A-Za-z]/,/^$/{/^$/d}' in.txt
</code></pre></div></div>
<p>to join lines ( en deletant les lignes blanches )</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -e '/./!d' -e '$!N;s/\n/ /' in.txt
sed -e '/./\!d' -e '$\!N;s/\n/ /' in.txt
grep "." in.txt | sed '$\!N;s/\n/ /'
</code></pre></div></div>
<p>to join lines ( en gardant les lignes blanches )</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -e '/./!b' -e '$!N;s/\n/ /' in.txt
sed -e '/./\!b' -e '$\!N;s/\n/ /' in.txt
grep "." in.txt | sed '$\!N;s/\n/ /' | sed G
</code></pre></div></div>
<h3 id="7-inserer">7-Inserer</h3>
<p>Inserer une ligne blanche apres chaque ligne</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed G in.txt
sed 'a\ ' in.txt
</code></pre></div></div>
<p>Inserer une ligne de tirets toutes les 2 lignes</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed 'n;a\----------' in.txt
</code></pre></div></div>
<p>Inserer une ligne blanche toutes les 3 lignes</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed 'n;n;G;' in.txt
</code></pre></div></div>
<p>Inserer une ligne blanche apres chaque ligne sauf apres la ligne 3</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed '3!G' in.txt
</code></pre></div></div>
<p>Inserer une ligne au debut, à la 3eme ligne et à la fin du fichier</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -e '1i \debut\ du\ traitement' in.txt
sed -e '3i \ajout\ a\ la\ 3eme\ ligne' in.txt
awk 'NR == 3 {print "line3"}1' in.txt
sed -e '$a \fin\ du\ traitement' in.txt
</code></pre></div></div>
<p>Inserer une ligne à un pattern</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -e '/pattern/ i\ligne ecrite avant le pattern' in.txt ............ (option 'i' : avant le pattern)
sed -e '/pattern/ a\ligne ecrite apres le pattern' in.txt ............ (option 'a' : apres le pattern)
</code></pre></div></div>
<p>Inserer une ligne blanche à un pattern</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -e '/pattern/ i\ ' in.txt ............ (option 'i' : avant le pattern)
sed -e '/pattern/ a\ ' in.txt ............ (option 'a' : apres le pattern)
</code></pre></div></div>
<p>Changer la ligne si elle contient un pattern</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -e '/pattern/ c\new line' in.txt
</code></pre></div></div>
<p>Inserer <strong>DELETED</strong> et supprimer les lignes entre 2 patterns</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed '/pattern1/,/pattern2/ c\**DELETED**' in.txt
</code></pre></div></div>
<p>Inserer la ligne line before avant chaque ligne du fichier</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -e 'i\line before' in.txt
</code></pre></div></div>
<p>Inserer du texte avant une ligne matchée par un pattern</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -e '/pattern/ i\line before pattern' in.txt
</code></pre></div></div>
<p>Inserer une ligne blanche avant une ligne matchée par un pattern</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed '/tata/{x;p;x}' in.txt
sed -e '/pattern/ i\ ' in.txt
</code></pre></div></div>
<p>Inserer une ligne blanche après une ligne matchée par un pattern</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed '/tata/G' in.txt
sed -e '/pattern/ a\ ' in.txt
</code></pre></div></div>
<p>Inserer une ligne blanche avant et apres une ligne matchee par un pattern</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed '/tata/{x;p;x;G}' in.txt
</code></pre></div></div>
<p>Inserer un fichier temp.txt</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed '1r temp.txt' &lt; in.txt ..........après la 1ère ligne de 'in.txt'
sed '/pattern/ r temp.txt' &lt; in.txt .........apres le pattern
</code></pre></div></div>
<p>Inserer un blanc devant toutes les lignes</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -e 's/^./ &amp;/g' in.txt
sed '{s_^_ _}' in.txt
</code></pre></div></div>
<p>Inserer un blanc à toutes les fins de lignes</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -e 's/.$/&amp; /g' in.txt
</code></pre></div></div>
<p>Inserer un blanc apres tous les t (a droite) en ligne 4</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -e '4s/t/&amp; /g' in.txt
sed -e '4\!s/t/&amp; /g' in.txt ........... #syntaxe inverse
</code></pre></div></div>
<p>Inserer au 5ème caractère après 3 caractères le signe # sur la ligne 2</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -r "2 ~ s/^(.{4})(.{3})/\2#/" in.txt
</code></pre></div></div>
<h3 id="8-remplacer-un-mot-par-un-autre-dans-un-ou-plusieurs-fichiers">8-Remplacer un MOT par un AUTRE dans un ou plusieurs fichiers</h3>
<p>REMPLACER UN MOT PAR UN AUTRE :</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sed -i 's/motachercher/nouveaumot/g' fichier.txt
</code></pre></div></div>
<p>REMPLACER UN MOT PAR UN AUTRE DE MANIERE RECURSIVE :</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>find /home/mumbly/MONREP/sousrep -type f -exec sed -i 's/windows/linux/g' {} +
</code></pre></div></div>
<p>RECHERCHER UN MOT DANS TOUS LES REPERTOIRES ET SOUS-REPERTOIRES (insensible à la casse : majuscule/minuscule) :</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>grep -i -l -r 'linux' /home/mumbly/MONREP/sousrep/
</code></pre></div></div>
<p>Comment chercher et remplacer dans plusieurs fichiers avec sed</p>
<p>Pour remplacer “echo htmlentities” par “highlight_string” dans tous les fichiers php du répertoire courant tapez ceci :</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sed -i 's/echo htmlentities/highlight_string/g' *.php
</code></pre></div></div>
<p>Alternative pour un chercher remplacer récursif :</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>find . -name "*.php" -exec sed -i 's/echo htmlentities/highlight_string/g' {} \;
</code></pre></div></div>
<h3 id="9-divers">9-divers</h3>
<p>Retirer les accents dun texte</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> cat non-ascii.txt | iconv -f utf8 -t ascii//TRANSLIT//IGNORE &gt; ascii.txt
</code></pre></div></div>
<p>Printer les lignes dun fichier2 qui ne sont pas dans le fichier1</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> comm -23 file2.txt file1.txt 2&gt;dev
grep -vxFf file1.txt file2.txt
</code></pre></div></div>
<p>Printer un fichier</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> cat in.txt
sed '' in.txt
sed ':' in.txt
</code></pre></div></div>
<p>Dupliquer toutes les lignes</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed 'p' in.txt
</code></pre></div></div>
<p>printer 3 fois chaque ligne</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed '{h;p;p}' in.txt
while read line;do for i in `seq 1 3`;do echo $line;done;done &lt; in.txt
</code></pre></div></div>
<p>Inverser lordre dun fichier</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> tac in.txt
sed -n '1!G;h;$p' in.txt
awk '{ a[i++]=$0 } END { for (j=i-1; j&gt;=0; ) print a[j--] }' in.txt
</code></pre></div></div>
<p>Ecrire 1 mot par ligne (pour 5 mots: -n5)</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> cat in.txt | xargs -n1
awk '{i=1; while (i&lt;=NF){print $i, " ";i++}}' in.txt
</code></pre></div></div>
<p>Ecrire un caractère par ligne</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> while read line; do echo -n "$line" | dd cbs=1 conv=unblock 2&gt;/dev/null; done &lt; in.txt
</code></pre></div></div>
<p>Ecrire un fichier sur une ligne</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed '{:a;$!N;s_\n_ _;ta}' in.txt
</code></pre></div></div>
<p>Joindre les lignes paires a la suite des lignes impaires</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed '$!N; s/\n/ /g' in.txt
</code></pre></div></div>
<p>Transforme les lignes en colonnes</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> awk '{printf "ligne%d: %s ",NR,$0&gt;"z-cible"}' z-source
</code></pre></div></div>
<p>Ajouter en prefixe le nombre doccurences des mots et trier</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> cat in.txt | xargs -n1 | sort | uniq -c | sort -nr
</code></pre></div></div>
<p>Print les 10 premiers (ou derniers) caracteres dun fichier</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> head -10c in.txt ........... #les 10 premiers
tail -10c in.txt ........... #les 10 derniers
</code></pre></div></div>
<p>Decoupe en n caracteres le fichier in.txt (ici n=10)</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> creation de fichiers: prefixe_outaa (outab..outac...)
split -b 10 in.txt prefixe_out
</code></pre></div></div>
<p>Decoupe en n lignes le fichier in.txt (ici n=5)</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> creation de fichiers: prefixe_outaa (outab..outac...)
split -l 5 in.txt prefix_out
awk '{print &gt;("prefix_out" int((NR+4)/5))}' in.txt
</code></pre></div></div>
<p>Trier un fichier dans un ordre numerique (-n); avec separateur (-t); colonne (-k); et place du caractere (.)</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> cat in.txt | sort -n -t" " -k2.4
dans un ordre decroissant (-r) et en retirant les doubles (-u) :
cat in.txt | sort -r -u
</code></pre></div></div>
<p>Copier un fichier</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> cp old_file new_file
sed 'w new_file' old_file
</code></pre></div></div>
<p>Definir un marqueur en fin de ligne (ici ,) qui joindra la ligne suivante</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed '/\,$/ {N; s_\,\n_ _}' in.txt
sed -e :a -e '/\,$/N; s_\,\n_ _; ta' in.txt
</code></pre></div></div>
<p>Si 1 ligne se termine par , joindre la suivante a elle</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -e :a -e '/,$/N ; s#\n## ; ta' in.txt
</code></pre></div></div>
<p>Si 1 ligne commence par un signe egale = , lajouter a la ligne precedente et remplacer le signe egale = par un espace</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -e :a -e '$!N;s/\n=/ /;ta' -e 'P;D' in.txt
</code></pre></div></div>
<p>“Dispach” (inverse du “regroupe”)</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> split en couples: ['colonne 1'-'parties[k]']
en 'k' fois nombre de lignes
awk '{key=$1;$1="";n=split($0, parties, "[,]");for(k=1; k&lt;=n; k++) print ""key" "1" "parties[k] ""}' in.txt| awk '{if($2&gt;0) print $0}' | awk '{if($1 != key){key = $1} else {$2 += cum} cum=$2; print}' &gt; out.txt
</code></pre></div></div>
<p>“Regroupe” (inverse du “dispach”)</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> (tous les elements semblables de la colonne 1
sont regroupes sur 1 seule ligne)
awk '{key=$1; $1=$2="";f[key]=f[key] s[key] $0;s[key]=","} END {for(key in f){gsub(/[[:space:]]/,"",f[key]);printf "%s %s\n",key,f[key]}}' in.txt| sort &gt; out.txt
</code></pre></div></div>
<p>Encadre le premier nombre de la ligne avec des ** , ne printer que ces lignes</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -n "s/\([0-9][0-9]*\)/**\1**/p" in.txt
</code></pre></div></div>
<p>Printer les lignes avec 3 digits consecutifs</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sed -n '/[0-9]\{3\}/p' in.txt
</code></pre></div></div>
<p>Inserer un espace entre chaque lettre</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> echo -e "bonjour"|sed 's/./&amp; /g' ................resultat: b o n j o u r
echo -e "bonjour"|sed -r 's/([^ ])/\1 /g'
echo -e "bonjour"|sed 's/\([^ ]\)/\1 /g'
</code></pre></div></div>
<p>dirname …………(en sous shell)</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> var="/home/Bureau/1/in.txt" ....... (en sous shell)
</code></pre></div></div>
<p>dirname $var ……….. —-&gt; /home/Bureau/1</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> echo ${var%/*} ........... ----&gt; /home/Bureau/1
</code></pre></div></div>
<p>basename ……. (en sous shell)</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> basename $var ........... ----&gt; in.txt
echo ${var##*/} ........... ----&gt; in.txt
</code></pre></div></div>
<p>while dans un sous shell (taper: sh)</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> while read line; do echo -en "$line\n"; done &lt; in.txt
while read line; do echo -e $line; done &lt; in.txt
</code></pre></div></div>
<p>set decoupe 1 variable en parametres positionnels dans un sous shell (taper: sh)</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> string="a b:c def:g"; IFS=':'; set $string; echo "$1"
</code></pre></div></div>
<p>read …$REPLY : equivalent de : head -1</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> read -r
</code></pre></div></div>
<p>Contenu des dossiers sans les sous dossiers</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> for fichier in *;do ls -al ;done
</code></pre></div></div>
<p>Contenu des dossiers avec les sous dossiers</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> for fichier in *;do ls -al "$fichier";done
</code></pre></div></div>
<table>
<tbody>
<tr>
<td>nombre de fichiers dans le repertoire courant (equivaut a: ls</td>
<td>wc -l)</td>
</tr>
</tbody>
</table>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> a=0;for i in *;do a=$(($a+1));done;echo nb=$a
</code></pre></div></div>
<p>apostrophe et guillemet</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> echo -n "your name is: "; read name ........... #taper: toto
echo 'hi $name' ........... #resultat : hi name
echo "hi $name" ........... #resultat : hi toto
</code></pre></div></div>
<p>par defaut, le separateur est blanc [Utiliser les parentheses () pour le sous shell]</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> echo "moi et moi, lui, les autres" | (read x y ;echo $y) ........... (-&gt;lui les autres)
</code></pre></div></div>
<p>nouveau separateur</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> IFS=",";echo "moi et moi, lui, les autres" | (read x y;echo $x) ........... (-&gt;moi et moi)
</code></pre></div></div>
<p>liste des variables denvironnement</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> export
</code></pre></div></div>
<p>detruire la valeur dune variable</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> (utiliser un sous shell en tapant: sh + return)
var=7 echo $var ........... -&gt; 7
unset var ........... -&gt; nothing
</code></pre></div></div>
<p>Concatenation (utiliser un sous shell en tapant: sh + return)</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> var=debut;echo ${var}ant ........... ----&gt;debutant
</code></pre></div></div>
<p>Commande set et shift (utiliser un sous shell en tapant: sh + return)</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> c="prof eleve classe note";set $c;echo $1 $2
........... ---&gt;prof eleve
c="prof eleve classe note";shift;echo $1 $2
........... ---&gt;eleve classe
</code></pre></div></div>
<p>Commande eval (utiliser un sous shell en tapant: sh + return)</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> message="date d'aujourd'hui?";set $message;echo $# .......#resultat: 2
message="date d'aujourd'hui?";set $message;echo $1 .......#resultat: date
message="date d'aujourd'hui?";set $message;eval $1 .......#resultat: dim 20 jan..
</code></pre></div></div>
<h3 id="note-sed">NOTE sed</h3>
<blockquote>
<p>Les exemples de <strong>sed</strong> ne font que modifier laffichage du fichier (sortie standard 1 = lécran).<br>
Pour des modifications permanentes avec les anciennes versions (inférieure à 4) utiliser un fichier temporaire<br>
Pour GNU sed utiliser le paramètre <strong>-i[suffixe]</strong> (<strong>in-place[=suffixe]</strong>), comme dans lexemple suivant <code class="language-plaintext highlighter-rouge">sed -i".bak" '3d' monFichier.txt</code> qui aura pour effet, de ne produire aucun affichage sur la sortie standard, de modifier le fichier original <em>monFichier.txt</em> en supprimant la 3ème ligne et de créer un fichier de sauvegarde nommé <em>monFichier.txt.bak</em></p>
</blockquote>
</div>
<div class="d-print-none">
<footer class="article__footer"><meta itemprop="dateModified" content="2020-02-08T00:00:00+01:00">
<!-- start custom article footer snippet -->
<!-- end custom article footer snippet -->
<!--
<div align="right"><a type="application/rss+xml" href="/feed.xml" title="S'abonner"><i class="fa fa-rss fa-2x"></i></a>
&emsp;</div>
-->
</footer>
<div class="article__section-navigator clearfix">
<div class="previous">
<span>PRÉCÉDENT</span><a href="/2020/01/20/Guide-installation-Nextcloud-17-(Debian-NGINX).html">Guide d'installation Nextcloud 17 et plus (Debian / NGINX)</a>
</div>
<div class="next">
<span>SUIVANT</span><a href="/2020/02/12/Mise-en-cache-nginx-OCSP-pour-corriger-erreur-firefox-premiere-connexion.html">Mise en cache nginx OCSP , pour éviter erreur firefox à la première connexion</a>
</div>
</div>
</div>
</div>
<script>(function() {
var SOURCES = window.TEXT_VARIABLES.sources;
window.Lazyload.js(SOURCES.jquery, function() {
$(function() {
var $this ,$scroll;
var $articleContent = $('.js-article-content');
var hasSidebar = $('.js-page-root').hasClass('layout--page--sidebar');
var scroll = hasSidebar ? '.js-page-main' : 'html, body';
$scroll = $(scroll);
$articleContent.find('.highlight').each(function() {
$this = $(this);
$this.attr('data-lang', $this.find('code').attr('data-lang'));
});
$articleContent.find('h1[id], h2[id], h3[id], h4[id], h5[id], h6[id]').each(function() {
$this = $(this);
$this.append($('<a class="anchor d-print-none" aria-hidden="true"></a>').html('<i class="fas fa-anchor"></i>'));
});
$articleContent.on('click', '.anchor', function() {
$scroll.scrollToAnchor('#' + $(this).parent().attr('id'), 400);
});
});
});
})();
</script>
</div>
<section class="page__comments d-print-none"></section></article><!-- start custom main bottom snippet -->
<!-- end custom main bottom snippet -->
</div>
</div></div></div>
</div>
</div>
<script>(function() {
var SOURCES = window.TEXT_VARIABLES.sources;
window.Lazyload.js(SOURCES.jquery, function() {
var $body = $('body'), $window = $(window);
var $pageRoot = $('.js-page-root'), $pageMain = $('.js-page-main');
var activeCount = 0;
function modal(options) {
var $root = this, visible, onChange, hideWhenWindowScroll = false;
var scrollTop;
function setOptions(options) {
var _options = options || {};
visible = _options.initialVisible === undefined ? false : show;
onChange = _options.onChange;
hideWhenWindowScroll = _options.hideWhenWindowScroll;
}
function init() {
setState(visible);
}
function setState(isShow) {
if (isShow === visible) {
return;
}
visible = isShow;
if (visible) {
activeCount++;
scrollTop = $(window).scrollTop() || $pageMain.scrollTop();
$root.addClass('modal--show');
$pageMain.scrollTop(scrollTop);
activeCount === 1 && ($pageRoot.addClass('show-modal'), $body.addClass('of-hidden'));
hideWhenWindowScroll && window.hasEvent('touchstart') && $window.on('scroll', hide);
$window.on('keyup', handleKeyup);
} else {
activeCount > 0 && activeCount--;
$root.removeClass('modal--show');
$window.scrollTop(scrollTop);
activeCount === 0 && ($pageRoot.removeClass('show-modal'), $body.removeClass('of-hidden'));
hideWhenWindowScroll && window.hasEvent('touchstart') && $window.off('scroll', hide);
$window.off('keyup', handleKeyup);
}
onChange && onChange(visible);
}
function show() {
setState(true);
}
function hide() {
setState(false);
}
function handleKeyup(e) {
// Char Code: 27 ESC
if (e.which === 27) {
hide();
}
}
setOptions(options);
init();
return {
show: show,
hide: hide,
$el: $root
};
}
$.fn.modal = modal;
});
})();
</script><div class="modal modal--overflow page__search-modal d-print-none js-page-search-modal">
<script>
(function () {
var SOURCES = window.TEXT_VARIABLES.sources;
window.Lazyload.js(SOURCES.jquery, function() {
// search panel
var search = (window.search || (window.search = {}));
var useDefaultSearchBox = window.useDefaultSearchBox === undefined ?
true : window.useDefaultSearchBox ;
var $searchModal = $('.js-page-search-modal');
var $searchToggle = $('.js-search-toggle');
var searchModal = $searchModal.modal({ onChange: handleModalChange, hideWhenWindowScroll: true });
var modalVisible = false;
search.searchModal = searchModal;
var $searchBox = null;
var $searchInput = null;
var $searchClear = null;
function getModalVisible() {
return modalVisible;
}
search.getModalVisible = getModalVisible;
function handleModalChange(visible) {
modalVisible = visible;
if (visible) {
search.onShow && search.onShow();
useDefaultSearchBox && $searchInput[0] && $searchInput[0].focus();
} else {
search.onShow && search.onHide();
useDefaultSearchBox && $searchInput[0] && $searchInput[0].blur();
setTimeout(function() {
useDefaultSearchBox && ($searchInput.val(''), $searchBox.removeClass('not-empty'));
search.clear && search.clear();
window.pageAsideAffix && window.pageAsideAffix.refresh();
}, 400);
}
}
$searchToggle.on('click', function() {
modalVisible ? searchModal.hide() : searchModal.show();
});
// Char Code: 83 S, 191 /
$(window).on('keyup', function(e) {
if (!modalVisible && !window.isFormElement(e.target || e.srcElement) && (e.which === 83 || e.which === 191)) {
modalVisible || searchModal.show();
}
});
if (useDefaultSearchBox) {
$searchBox = $('.js-search-box');
$searchInput = $searchBox.children('input');
$searchClear = $searchBox.children('.js-icon-clear');
search.getSearchInput = function() {
return $searchInput.get(0);
};
search.getVal = function() {
return $searchInput.val();
};
search.setVal = function(val) {
$searchInput.val(val);
};
$searchInput.on('focus', function() {
$(this).addClass('focus');
});
$searchInput.on('blur', function() {
$(this).removeClass('focus');
});
$searchInput.on('input', window.throttle(function() {
var val = $(this).val();
if (val === '' || typeof val !== 'string') {
search.clear && search.clear();
} else {
$searchBox.addClass('not-empty');
search.onInputNotEmpty && search.onInputNotEmpty(val);
}
}, 400));
$searchClear.on('click', function() {
$searchInput.val(''); $searchBox.removeClass('not-empty');
search.clear && search.clear();
});
}
});
})();
</script><div class="search search--dark">
<div class="main">
<div class="search__header">Recherche</div>
<div class="search-bar">
<div class="search-box js-search-box">
<div class="search-box__icon-search"><i class="fas fa-search"></i></div>
<input id="search-input" type="text">
<div class="search-box__icon-clear js-icon-clear">
<a><i class="fas fa-times"></i></a>
</div>
</div>
<button class="button button--theme-dark button--pill search__cancel js-search-toggle">
Annuler</button>
</div>
<div id="results-container" class="search-result js-search-result"></div>
</div>
</div>
<!-- Script pointing to search-script.js -->
<script>/*!
* Simple-Jekyll-Search
* Copyright 2015-2020, Christian Fei
* Licensed under the MIT License.
*/
(function(){
'use strict'
var _$Templater_7 = {
compile: compile,
setOptions: setOptions
}
const options = {}
options.pattern = /\{(.*?)\}/g
options.template = ''
options.middleware = function () {}
function setOptions (_options) {
options.pattern = _options.pattern || options.pattern
options.template = _options.template || options.template
if (typeof _options.middleware === 'function') {
options.middleware = _options.middleware
}
}
function compile (data) {
return options.template.replace(options.pattern, function (match, prop) {
const value = options.middleware(prop, data[prop], options.template)
if (typeof value !== 'undefined') {
return value
}
return data[prop] || match
})
}
'use strict';
function fuzzysearch (needle, haystack) {
var tlen = haystack.length;
var qlen = needle.length;
if (qlen > tlen) {
return false;
}
if (qlen === tlen) {
return needle === haystack;
}
outer: for (var i = 0, j = 0; i < qlen; i++) {
var nch = needle.charCodeAt(i);
while (j < tlen) {
if (haystack.charCodeAt(j++) === nch) {
continue outer;
}
}
return false;
}
return true;
}
var _$fuzzysearch_1 = fuzzysearch;
'use strict'
/* removed: const _$fuzzysearch_1 = require('fuzzysearch') */;
var _$FuzzySearchStrategy_5 = new FuzzySearchStrategy()
function FuzzySearchStrategy () {
this.matches = function (string, crit) {
return _$fuzzysearch_1(crit.toLowerCase(), string.toLowerCase())
}
}
'use strict'
var _$LiteralSearchStrategy_6 = new LiteralSearchStrategy()
function LiteralSearchStrategy () {
this.matches = function (str, crit) {
if (!str) return false
str = str.trim().toLowerCase()
crit = crit.trim().toLowerCase()
return crit.split(' ').filter(function (word) {
return str.indexOf(word) >= 0
}).length === crit.split(' ').length
}
}
'use strict'
var _$Repository_4 = {
put: put,
clear: clear,
search: search,
setOptions: __setOptions_4
}
/* removed: const _$FuzzySearchStrategy_5 = require('./SearchStrategies/FuzzySearchStrategy') */;
/* removed: const _$LiteralSearchStrategy_6 = require('./SearchStrategies/LiteralSearchStrategy') */;
function NoSort () {
return 0
}
const data = []
let opt = {}
opt.fuzzy = false
opt.limit = 10
opt.searchStrategy = opt.fuzzy ? _$FuzzySearchStrategy_5 : _$LiteralSearchStrategy_6
opt.sort = NoSort
opt.exclude = []
function put (data) {
if (isObject(data)) {
return addObject(data)
}
if (isArray(data)) {
return addArray(data)
}
return undefined
}
function clear () {
data.length = 0
return data
}
function isObject (obj) {
return Boolean(obj) && Object.prototype.toString.call(obj) === '[object Object]'
}
function isArray (obj) {
return Boolean(obj) && Object.prototype.toString.call(obj) === '[object Array]'
}
function addObject (_data) {
data.push(_data)
return data
}
function addArray (_data) {
const added = []
clear()
for (let i = 0, len = _data.length; i < len; i++) {
if (isObject(_data[i])) {
added.push(addObject(_data[i]))
}
}
return added
}
function search (crit) {
if (!crit) {
return []
}
return findMatches(data, crit, opt.searchStrategy, opt).sort(opt.sort)
}
function __setOptions_4 (_opt) {
opt = _opt || {}
opt.fuzzy = _opt.fuzzy || false
opt.limit = _opt.limit || 10
opt.searchStrategy = _opt.fuzzy ? _$FuzzySearchStrategy_5 : _$LiteralSearchStrategy_6
opt.sort = _opt.sort || NoSort
opt.exclude = _opt.exclude || []
}
function findMatches (data, crit, strategy, opt) {
const matches = []
for (let i = 0; i < data.length && matches.length < opt.limit; i++) {
const match = findMatchesInObject(data[i], crit, strategy, opt)
if (match) {
matches.push(match)
}
}
return matches
}
function findMatchesInObject (obj, crit, strategy, opt) {
for (const key in obj) {
if (!isExcluded(obj[key], opt.exclude) && strategy.matches(obj[key], crit)) {
return obj
}
}
}
function isExcluded (term, excludedTerms) {
for (let i = 0, len = excludedTerms.length; i < len; i++) {
const excludedTerm = excludedTerms[i]
if (new RegExp(excludedTerm).test(term)) {
return true
}
}
return false
}
/* globals ActiveXObject:false */
'use strict'
var _$JSONLoader_2 = {
load: load
}
function load (location, callback) {
const xhr = getXHR()
xhr.open('GET', location, true)
xhr.onreadystatechange = createStateChangeListener(xhr, callback)
xhr.send()
}
function createStateChangeListener (xhr, callback) {
return function () {
if (xhr.readyState === 4 && xhr.status === 200) {
try {
callback(null, JSON.parse(xhr.responseText))
} catch (err) {
callback(err, null)
}
}
}
}
function getXHR () {
return window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP')
}
'use strict'
var _$OptionsValidator_3 = function OptionsValidator (params) {
if (!validateParams(params)) {
throw new Error('-- OptionsValidator: required options missing')
}
if (!(this instanceof OptionsValidator)) {
return new OptionsValidator(params)
}
const requiredOptions = params.required
this.getRequiredOptions = function () {
return requiredOptions
}
this.validate = function (parameters) {
const errors = []
requiredOptions.forEach(function (requiredOptionName) {
if (typeof parameters[requiredOptionName] === 'undefined') {
errors.push(requiredOptionName)
}
})
return errors
}
function validateParams (params) {
if (!params) {
return false
}
return typeof params.required !== 'undefined' && params.required instanceof Array
}
}
'use strict'
var _$utils_9 = {
merge: merge,
isJSON: isJSON
}
function merge (defaultParams, mergeParams) {
const mergedOptions = {}
for (const option in defaultParams) {
mergedOptions[option] = defaultParams[option]
if (typeof mergeParams[option] !== 'undefined') {
mergedOptions[option] = mergeParams[option]
}
}
return mergedOptions
}
function isJSON (json) {
try {
if (json instanceof Object && JSON.parse(JSON.stringify(json))) {
return true
}
return false
} catch (err) {
return false
}
}
var _$src_8 = {};
(function (window) {
'use strict'
let options = {
searchInput: null,
resultsContainer: null,
json: [],
success: Function.prototype,
searchResultTemplate: '<li><a href="{url}" title="{desc}">{title}</a></li>',
templateMiddleware: Function.prototype,
sortMiddleware: function () {
return 0
},
noResultsText: 'No results found',
limit: 10,
fuzzy: false,
debounceTime: null,
exclude: []
}
let debounceTimerHandle
const debounce = function (func, delayMillis) {
if (delayMillis) {
clearTimeout(debounceTimerHandle)
debounceTimerHandle = setTimeout(func, delayMillis)
} else {
func.call()
}
}
const requiredOptions = ['searchInput', 'resultsContainer', 'json']
/* removed: const _$Templater_7 = require('./Templater') */;
/* removed: const _$Repository_4 = require('./Repository') */;
/* removed: const _$JSONLoader_2 = require('./JSONLoader') */;
const optionsValidator = _$OptionsValidator_3({
required: requiredOptions
})
/* removed: const _$utils_9 = require('./utils') */;
window.SimpleJekyllSearch = function (_options) {
const errors = optionsValidator.validate(_options)
if (errors.length > 0) {
throwError('You must specify the following required options: ' + requiredOptions)
}
options = _$utils_9.merge(options, _options)
_$Templater_7.setOptions({
template: options.searchResultTemplate,
middleware: options.templateMiddleware
})
_$Repository_4.setOptions({
fuzzy: options.fuzzy,
limit: options.limit,
sort: options.sortMiddleware,
exclude: options.exclude
})
if (_$utils_9.isJSON(options.json)) {
initWithJSON(options.json)
} else {
initWithURL(options.json)
}
const rv = {
search: search
}
typeof options.success === 'function' && options.success.call(rv)
return rv
}
function initWithJSON (json) {
_$Repository_4.put(json)
registerInput()
}
function initWithURL (url) {
_$JSONLoader_2.load(url, function (err, json) {
if (err) {
throwError('failed to get JSON (' + url + ')')
}
initWithJSON(json)
})
}
function emptyResultsContainer () {
options.resultsContainer.innerHTML = ''
}
function appendToResultsContainer (text) {
options.resultsContainer.innerHTML += text
}
function registerInput () {
options.searchInput.addEventListener('input', function (e) {
if (isWhitelistedKey(e.which)) {
emptyResultsContainer()
debounce(function () { search(e.target.value) }, options.debounceTime)
}
})
}
function search (query) {
if (isValidQuery(query)) {
emptyResultsContainer()
render(_$Repository_4.search(query), query)
}
}
function render (results, query) {
const len = results.length
if (len === 0) {
return appendToResultsContainer(options.noResultsText)
}
for (let i = 0; i < len; i++) {
results[i].query = query
appendToResultsContainer(_$Templater_7.compile(results[i]))
}
}
function isValidQuery (query) {
return query && query.length > 0
}
function isWhitelistedKey (key) {
return [13, 16, 20, 37, 38, 39, 40, 91].indexOf(key) === -1
}
function throwError (message) {
throw new Error('SimpleJekyllSearch --- ' + message)
}
})(window)
}());
</script>
<!-- Configuration -->
<script>
SimpleJekyllSearch({
searchInput: document.getElementById('search-input'),
resultsContainer: document.getElementById('results-container'),
noResultsText: '<p>Aucun résultat!</p>',
json: '/search.json',
searchResultTemplate: '<li><a href="{url}">{date}&nbsp;{title}</a>&nbsp;(Création {create})</li>'
})
</script>
</div>
</div>
<script>(function() {
var SOURCES = window.TEXT_VARIABLES.sources;
window.Lazyload.js(SOURCES.jquery, function() {
function scrollToAnchor(anchor, duration, callback) {
var $root = this;
$root.animate({ scrollTop: $(anchor).position().top }, duration, function() {
window.history.replaceState(null, '', window.location.href.split('#')[0] + anchor);
callback && callback();
});
}
$.fn.scrollToAnchor = scrollToAnchor;
});
})();
(function() {
var SOURCES = window.TEXT_VARIABLES.sources;
window.Lazyload.js(SOURCES.jquery, function() {
function affix(options) {
var $root = this, $window = $(window), $scrollTarget, $scroll,
offsetBottom = 0, scrollTarget = window, scroll = window.document, disabled = false, isOverallScroller = true,
rootTop, rootLeft, rootHeight, scrollBottom, rootBottomTop,
hasInit = false, curState;
function setOptions(options) {
var _options = options || {};
_options.offsetBottom && (offsetBottom = _options.offsetBottom);
_options.scrollTarget && (scrollTarget = _options.scrollTarget);
_options.scroll && (scroll = _options.scroll);
_options.disabled !== undefined && (disabled = _options.disabled);
$scrollTarget = $(scrollTarget);
isOverallScroller = window.isOverallScroller($scrollTarget[0]);
$scroll = $(scroll);
}
function preCalc() {
top();
rootHeight = $root.outerHeight();
rootTop = $root.offset().top + (isOverallScroller ? 0 : $scrollTarget.scrollTop());
rootLeft = $root.offset().left;
}
function calc(needPreCalc) {
needPreCalc && preCalc();
scrollBottom = $scroll.outerHeight() - offsetBottom - rootHeight;
rootBottomTop = scrollBottom - rootTop;
}
function top() {
if (curState !== 'top') {
$root.removeClass('fixed').css({
left: 0,
top: 0
});
curState = 'top';
}
}
function fixed() {
if (curState !== 'fixed') {
$root.addClass('fixed').css({
left: rootLeft + 'px',
top: 0
});
curState = 'fixed';
}
}
function bottom() {
if (curState !== 'bottom') {
$root.removeClass('fixed').css({
left: 0,
top: rootBottomTop + 'px'
});
curState = 'bottom';
}
}
function setState() {
var scrollTop = $scrollTarget.scrollTop();
if (scrollTop >= rootTop && scrollTop <= scrollBottom) {
fixed();
} else if (scrollTop < rootTop) {
top();
} else {
bottom();
}
}
function init() {
if(!hasInit) {
var interval, timeout;
calc(true); setState();
// run calc every 100 millisecond
interval = setInterval(function() {
calc();
}, 100);
timeout = setTimeout(function() {
clearInterval(interval);
}, 45000);
window.pageLoad.then(function() {
setTimeout(function() {
clearInterval(interval);
clearTimeout(timeout);
}, 3000);
});
$scrollTarget.on('scroll', function() {
disabled || setState();
});
$window.on('resize', function() {
disabled || (calc(true), setState());
});
hasInit = true;
}
}
setOptions(options);
if (!disabled) {
init();
}
$window.on('resize', window.throttle(function() {
init();
}, 200));
return {
setOptions: setOptions,
refresh: function() {
calc(true, { animation: false }); setState();
}
};
}
$.fn.affix = affix;
});
})();
(function() {
var SOURCES = window.TEXT_VARIABLES.sources;
window.Lazyload.js(SOURCES.jquery, function() {
function toc(options) {
var $root = this, $window = $(window), $scrollTarget, $scroller, $tocUl = $('<ul class="toc toc--ellipsis"></ul>'), $tocLi, $headings, $activeLast, $activeCur,
selectors = 'h1,h2,h3', container = 'body', scrollTarget = window, scroller = 'html, body', disabled = false,
headingsPos, scrolling = false, hasRendered = false, hasInit = false;
function setOptions(options) {
var _options = options || {};
_options.selectors && (selectors = _options.selectors);
_options.container && (container = _options.container);
_options.scrollTarget && (scrollTarget = _options.scrollTarget);
_options.scroller && (scroller = _options.scroller);
_options.disabled !== undefined && (disabled = _options.disabled);
$headings = $(container).find(selectors).filter('[id]');
$scrollTarget = $(scrollTarget);
$scroller = $(scroller);
}
function calc() {
headingsPos = [];
$headings.each(function() {
headingsPos.push(Math.floor($(this).position().top));
});
}
function setState(element, disabled) {
var scrollTop = $scrollTarget.scrollTop(), i;
if (disabled || !headingsPos || headingsPos.length < 1) { return; }
if (element) {
$activeCur = element;
} else {
for (i = 0; i < headingsPos.length; i++) {
if (scrollTop >= headingsPos[i]) {
$activeCur = $tocLi.eq(i);
} else {
$activeCur || ($activeCur = $tocLi.eq(i));
break;
}
}
}
$activeLast && $activeLast.removeClass('active');
($activeLast = $activeCur).addClass('active');
}
function render() {
if(!hasRendered) {
$root.append($tocUl);
$headings.each(function() {
var $this = $(this);
$tocUl.append($('<li></li>').addClass('toc-' + $this.prop('tagName').toLowerCase())
.append($('<a></a>').text($this.text()).attr('href', '#' + $this.prop('id'))));
});
$tocLi = $tocUl.children('li');
$tocUl.on('click', 'a', function(e) {
e.preventDefault();
var $this = $(this);
scrolling = true;
setState($this.parent());
$scroller.scrollToAnchor($this.attr('href'), 400, function() {
scrolling = false;
});
});
}
hasRendered = true;
}
function init() {
var interval, timeout;
if(!hasInit) {
render(); calc(); setState(null, scrolling);
// run calc every 100 millisecond
interval = setInterval(function() {
calc();
}, 100);
timeout = setTimeout(function() {
clearInterval(interval);
}, 45000);
window.pageLoad.then(function() {
setTimeout(function() {
clearInterval(interval);
clearTimeout(timeout);
}, 3000);
});
$scrollTarget.on('scroll', function() {
disabled || setState(null, scrolling);
});
$window.on('resize', window.throttle(function() {
if (!disabled) {
render(); calc(); setState(null, scrolling);
}
}, 100));
}
hasInit = true;
}
setOptions(options);
if (!disabled) {
init();
}
$window.on('resize', window.throttle(function() {
init();
}, 200));
return {
setOptions: setOptions
};
}
$.fn.toc = toc;
});
})();
/*(function () {
})();*/
</script><script>
/* toc must before affix, since affix need to konw toc' height. */(function() {
var SOURCES = window.TEXT_VARIABLES.sources;
var TOC_SELECTOR = window.TEXT_VARIABLES.site.toc.selectors;
window.Lazyload.js(SOURCES.jquery, function() {
var $window = $(window);
var $articleContent = $('.js-article-content');
var $tocRoot = $('.js-toc-root'), $col2 = $('.js-col-aside');
var toc;
var tocDisabled = false;
var hasSidebar = $('.js-page-root').hasClass('layout--page--sidebar');
var hasToc = $articleContent.find(TOC_SELECTOR).length > 0;
function disabled() {
return $col2.css('display') === 'none' || !hasToc;
}
tocDisabled = disabled();
toc = $tocRoot.toc({
selectors: TOC_SELECTOR,
container: $articleContent,
scrollTarget: hasSidebar ? '.js-page-main' : null,
scroller: hasSidebar ? '.js-page-main' : null,
disabled: tocDisabled
});
$window.on('resize', window.throttle(function() {
tocDisabled = disabled();
toc && toc.setOptions({
disabled: tocDisabled
});
}, 100));
});
})();
(function() {
var SOURCES = window.TEXT_VARIABLES.sources;
window.Lazyload.js(SOURCES.jquery, function() {
var $window = $(window), $pageFooter = $('.js-page-footer');
var $pageAside = $('.js-page-aside');
var affix;
var tocDisabled = false;
var hasSidebar = $('.js-page-root').hasClass('layout--page--sidebar');
affix = $pageAside.affix({
offsetBottom: $pageFooter.outerHeight(),
scrollTarget: hasSidebar ? '.js-page-main' : null,
scroller: hasSidebar ? '.js-page-main' : null,
scroll: hasSidebar ? $('.js-page-main').children() : null,
disabled: tocDisabled
});
$window.on('resize', window.throttle(function() {
affix && affix.setOptions({
disabled: tocDisabled
});
}, 100));
window.pageAsideAffix = affix;
});
})();
</script><!---->
</div>
<script>(function () {
var $root = document.getElementsByClassName('root')[0];
if (window.hasEvent('touchstart')) {
$root.dataset.isTouch = true;
document.addEventListener('touchstart', function(){}, false);
}
})();
</script>
</body>
</html>