Script snippets for piping commands
The following scripts do nice things as a part of a pipe.
Table 1.26. List of script snippets for piping commands
script snippet (type in one line) |
effect of command |
|find /usr -print | find all files under "/usr" |
|seq 1 100 | print 1 to 100 |
| xargs -n 1 <command> | run command repeatedly with each item from pipe as its argument |
| xargs -n 1 echo | split white-space-separated items from pipe into lines |
| xargs echo | merge all lines from pipe into a line |
| grep -e <regex_pattern> | extract lines from pipe containing <regex_pattern> |
| grep -v -e <regex_pattern> | extract lines from pipe not containing <regex_pattern> |
| cut -d: -f3 - | extract third field from pipe separated by ":" (passwd file etc.) |
| awk '{ print $3 }' | extract third field from pipe separated by whitespaces |
| awk -F'\t' '{ print $3 }' | extract third field from pipe separated by tab |
| col -bx | remove backspace and expand tabs to spaces |
| expand - | expand tabs |
| sort| uniq | sort and remove duplicates |
| tr 'A-Z' 'a-z' | convert uppercase to lowercase |
| tr -d '\n' | concatenate lines into one line |
| tr -d '\r' | remove CR |
| sed 's/^/# /' | add "#" to the start of each line |
| sed 's/\.ext//g' | remove ".ext" |
| sed -n -e 2p | print the second line |
| head -n 2 - | print the first 2 lines |
| tail -n 2 - | print the last 2 lines |
No comments:
Post a Comment