Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Mail Systems
Eclipse Documentation

How To Guides
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Problem Solutions
Privacy Policy




Debian GNU/Linux Reference Guide
Prev Home Next

8.6.18 Script snippets for piping commands

The following scripts will do nice things as a part of a pipe.

     find /usr | egrep -v "/usr/var|/usr/tmp|/usr/local"
                          # find all files in /usr excluding some files
     xargs -n 1 command   # run command for all items from stdin
     xargs -n 1 echo |    # split white-space-separated items into lines
     xargs echo      |    # merge all lines into a line
     grep -e pattern|     # extract lines containing pattern
     cut -d: -f3 -|
             # extract third field separated by : (passwd file etc.)
     awk '{ print $3 }' | # extract third field separated by whitespaces
     awk -F'\t' '{ print $3 }' |
             # extract third field separated by tab
     col -bx |            # remove backspace and expand tabs to spaces
     expand -|            # expand tabs
     sort -u|             # sort and remove duplicates
     tr '\n' ' '|         # concatenate lines into one line
     tr '\r' ''|          # remove CR
     tr 'A-Z' 'a-z'|      # convert uppercase to lowercase
     sed 's/^/# /'|       # make each line a comment
     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

Debian GNU/Linux Reference Guide
Prev Home Next

  Published under the terms of the GNU General Public License Design by Interspire