shell基础知识
来源:互联网 发布:关系数据库语言的特点 编辑:程序博客网 时间:2024/05/16 16:58
/////////////////////////////////////////////////////////////////////////////////////////////
如何用Shell命令从一个文件中读取数据到变量中
/////////////////////////////////////////////////////////////////////////////////////////////
#!/bin/bash
while read line
do
i=$line
done<file
#file是要读的文件,行内容已经到i中
#循环读文件中每行的内容赋到i变量中
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
用awk如何显示和读取文件的最后一行
/////////////////////////////////////////////////////////////////////////////////////////////
#在终端显示文件(filename为要显示的文件名)的最后一行
awk '{a=$0} END{print a}' filename
#在终端显示文件(filename)的最后一行的某个域(n表示第几个域,从1开始)
awk '{a=$0} END{print $n}' filename
#读取文件最后一行的某个域(或整行)到变量variable中
variable=`awk '{a=$0};END {print $n}' filename`
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
获取时间到变量中
/////////////////////////////////////////////////////////////////////////////////////////////
#获取时间到变量timenow中 ,并指定格式为HH:MM:SS
timenow=`date '+%H:%M:%S'`
#获取时间到变量TimeLastSecond中,获取是自1970 1.1 0:0开始的秒数
TimeLastSecond=`date '+%s'`
#更多关于时间的操作见date命令选项
#注意符号" ' "和" ` ",前者是双引号在英文输入法下的那个键,而后者是在英文输入法下的~那个键
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
用shell实现读取文件中每行各个字段的内容
/////////////////////////////////////////////////////////////////////////////////////////////
while read line
do
t1=`echo "$line" | awk -F ',' '{print $1}'`
t2=`echo "$line" | awk -F ',' '{print $2}'`
t3=`echo "$line" | awk -F ',' '{print $3}'`
echo $t1
echo $t2
echo $t3
done < text.txt
#
#==============================================================
#Description : This script is used to record thd terminal restart count,which
# testing the 128M NAND FLASH or other NAND FLASH
# U can change the directory and filename if need
# **Test nand flash**
#
#Author : reille
#Created : 2009.6.5
#Version : V1.0
#==============================================================
#
#
###[START]###
#define the file directory
DIR=/mnt/update/
#DIR=/root/reille/
#define the file name
FILENAME=restart_count.txt
restart_count=0
#system time now
timenow=`date '+%H:%M:%S'`
#system time(seconds) now and last restart
TimeNowSecond=0
TimeLastSecond=0
#the interval between this restart and last restart
interval=0
if [ -e $FILENAME ]; then
if [ -r $FILENAME ]; then
restart_count=`awk '{a=$0};END {print $1}' $FILENAME`
TimeLastSecond=`awk '{a=$0};END {print $3}' $FILENAME`
echo "last total restart count=$restart_count"
echo "last system seconds=$TimeLastSecond"
awk '{a=$0};END {print $4}' $FILENAME
echo "======================================="
fi
else
echo "First run and file don't exit, so create the file"
restart_count=0
TimeLastSecond=`date '+%s'`
touch $FILENAME
fi
if [ -w $FILENAME ]; then
restart_count=$(($restart_count + 1))
echo "refresh restart count to $restart_count"
temp=`date '+%s'`
echo "current system seconds=$temp"
interval=$(($temp - $TimeLastSecond))
echo "Interval=$interval"
echo -e "$restart_count `date '+%H:%M:%S'` `date '+%s'` $interval" >>$FILENAME
echo "*********************************************"
fi
#
###[END]####
#
#
#
- shell基础知识
- shell基础知识
- shell基础知识
- SHELL 基础知识
- Shell 基础知识
- shell基础知识
- shell基础知识
- shell 基础知识
- shell 基础知识
- shell 基础知识
- Shell基础知识
- Shell基础知识
- shell基础知识
- shell基础知识
- shell基础知识
- shell基础知识
- shell基础知识
- shell 基础知识
- 一条IP排序的SQL语句
- 一个睡五分钟等于六个钟头的方法
- CUDA 安装指引 for Linux
- linux下用C获取IP地址
- Oracle RAC工作原理
- shell基础知识
- 在嵌入式开发环境里调试,用gdb和gdbserver调试应用程序。
- 游戏程序开发基础(客户端篇)之一
- 解压缩
- 一生中最有价值的10样东西
- Head First C# 中文版 第10章 异常处理 翻译完毕 PDF下载
- javascript日志工具-Lumberjack 介绍
- 设计中
- Vector用法(C++ Primer中文版)