---
title: "Several Frequently Used Commands"
author: "whitesock"
date: "2011-10-13T11:35:12Z"
tags: ["Linux", "awk", "sed"]
categories: ["操作系统"]
slug: "several-frequently-used-commands"
draft: false
lastmod: "2012-04-12T10:55:51Z"
id: 1194066
url: "https://whitesock.iteye.com/blog/1194066"
---

sed '/^\\s\*$/d' a.txt # delete ALL blank lines  
sed '/./,$!d' a.txt # delete all leading blank lines at top of file

 

sed '=' a.txt | sed 'N;s/\\n/\\t/' # cat -n a.txt

sed '/./=' a.txt | sed '/./N; s/\\n/\\t/' # number each not blank line of file

 

sed '1!G;h;$!d' a.txt # reverse order of lines

sed '/./,$!d' a.txt # delete all leading blank lines at top of file

sed '$!N; /^\\(.\*\\)\\n\\1$/!P; D' a.txt # delete duplicate, consecutive lines

 

gawk '$1~/\[0-9].\*/{total += $2} END{print total}' a.txt  
gawk 'BEGIN {"cat c.txt | wc -l"|getline n} n&gt;10 {print}' a.txt

ls | gawk -F. '{system("mv " $0 " " sprintf("%03d", $1) "." $2)}