Unix Shell, and how to read the file line by line analysis

Read the file by line:

while read myline
  echo $myline
done < /etc/passwd

This procedure is to enter a file / etc / passwd one output.

If we only need to output it username and home directory, this time need to parse the file.
Each line is probably as follows, to: as a column separator, the first column is the user name, the sixth column is the home directory

ecrane:!:300801:1:Eric Crane =ecrane@us.ibm.com:/home/ecrane:/usr/bin/ksh

We only need to print the two columns on it:

while read myline
  echo $myline|cut -d: -f1,6
done < /etc/passwd

The procedure is simple,-d: is the development of a separator for the:,-f1, 6 was designated the first operation, the sixth column.

Of course, we still have a way to use the awk command:

while read myline
  echo $myline|awk -F: '{print $1,$6}'
done < /etc/passwd
分类:OS 时间:2010-04-06 人气:227
blog comments powered by Disqus


  • In the Windows system directory to mount UNIX NFS share 2010-02-16

    Taken from: http://cha.homeip.net/blog/archives/2005/11/_windows_unix_n.html This is a very interesting tool, Microsoft do have access to Linux NFS tools, many functions. Microsoft's site said: https: / / www.microsoft.com/taiwan/windows/sfu/ Windows

  • linux Shell入门:掌握Linux,OS X,Unix的Shell环境 2014-07-01

    这篇文章主要介绍了linux Shell入门:掌握Linux,OS X,Unix的Shell环境 ,需要的朋友可以参考下 在Linux或类Unix系统中,每个用户和进程都运行在一个特定环境中.这个环境包含了变量.设置.别名.函数以及更多的东西.下面是对Shell环境下一些常用命令的简单介绍,包括每个命令如何使用的例子,以及在命令行下设定你自己的环境来提高效率. 找出你当前的shell 在终端应用中输入下面命令中的任意一个: ps $$ ps -p $$ 或者 echo "$0" 输出范

  • 送给Shell兄弟姐妹们的节日礼物:用awk来示爱 2014-12-18

    送给Shell版兄弟姐妹们的节日礼物 有好一段时间不来了,怪想大家的. 眼看快到十月一了,写了两个awk程序作为礼物送给shell版的兄弟姐妹们,祝大家节日愉快! 注:若转载请保持程序的完整,谢谢! 程序一: 彩色显示文件程序,每个字符的颜色都不一样,随机变化,让你看花眼睛^_^: 程序代码: #! /usr/bin/awk # Write by dbcat # EMail:[email protected] # run : awk -f ColorCat.awk YourFile BEGIN{

  • "" (Double quotes) and''(single quotes) the difference between 2011-09-17

    Or come back to our command line after the previous study, should be very clear when you shell prompt back on the keyboard until you press enter, you enter text that is command line, and then shell will be executed by the process you submit the order

  • Under unix shell programming (1) 2010-06-11

    * Shell What is this? Any invention has for user interface. User interface for UNIX is the Shell (DOS's command are familiar with it, but more powerful UNIX-to). Shell provides the user input commands and command parameters may be the result of the e

  • Under unix shell programming (2) 2010-06-11

    3> use the data variables in the Shell Users can use the data variables in the Shell, for example ba.sh procedures: cd / usr / icewalk ls | cpio-o> / dev/fd0 The procedure to back up the directory as a constant, that the program can only be used to

  • Under unix shell programming (3) 2010-06-11

    Until statement While the statement, as long as certain conditions are true, then repeat the cycle of the code, until just the same while the opposite statement, the statement repeats the code to loop until a condition is true face only to stop. Unti

  • linux and unix shell programming guide 2010-10-09

    linux and unix shell programming guide Preface Introduction Part translator directory shell Chapter 1, file security and permissions 1 1.1 Paper 1 1.2 File Type 2 1.3 Permissions 2 1.4 change the permissions bit 4 1.4.1 Symbolic Mode 4 1.4.2 chmod co

  • Unix Shell Scripting of 'literacy articles' 2011-06-07

    Unix Shell Scripting of 'literacy articles' - [ cutting edge ] Tag: cutting edge of technology Copyright : reprint, please indicate the form of hyperlinks original source of article and author information and this statement http://bigwhite.blogbus.co

  • Unix / Linux system in the shell 2011-01-12

    For the initial contact with Unix / Linux system, classmates, Unix / Linux system and Windows system, the biggest difference is that operating Unix / Linux systems more often than using the GUI graphical interface but the use of shell command line. T

iOS 开发

Android 开发

Python 开发



PHP 开发

Ruby 开发






Javascript 开发

.NET 开发



Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 黔ICP备15002463号-1

processed in 0.170 (s). 12 q(s)