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

Read the file by line:

while read myline
do
  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
do
  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
do
  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入门:掌握Linux,OS X,Unix的Shell环境 2014-04-23

    在Linux或类Unix系统中,每个用户和进程都运行在一个特定环境中.这个环境包含了变量.设置.别名.函数以及更多的东西.下面是对Shell环境下一些常用命令的简单介绍,包括每个命令如何使用的例子,以及在命令行下设定你自己的环境来提高效率. 找出你当前的shell 在终端应用中输入下面命令中的任意一个: ps $$ ps -p $$ 或者 echo "$0" 输出范例: 图1:找出当前的shell 找出所有已安装的shell 找到已安装shell的完整路径: type -a zsh t

  • [unix]unix I/O知识 2013-03-17

    0.UNIX输入输出基本概念 Q1.程序与文件建立连接或通信有几种机制?流与文件描述字有什么区别? Q2.打开文件的实质? 打开文件就是程序与文件之间建立连接或通信. 流的类型是FILE: 文件描述字的类型是int: 流函数建立在文件描述字之上. 1.标准I/O [针对流] a. NULL b.流与FILE对象 c.打开与关闭流 d.读写流 {读的方式不同:写的方式不同} e.文件定位 f.文件结束和错误指示器 为了区分究竟是错误返回还是文件返回.ferror()确定是否存在错误:feof()检

  • "" (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

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

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

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

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