SHELL脚本读文件

先说一下,我用的是这个:

 

以下是sh文件内容

********************************************

#!/bin/sh
FILENAME="$1"

cat $FILENAME | while read LINE
do
        echo "$LINE"

done

********************************************

 

给你写了一个小例子,从一个文件读数据,设置环境变量:
数据文件data.txt包含三行:
aaa
bbb
ccc


------   test.sh   ------
while   read   data;   do
        if   [   $data   =   "ccc "   ];   then
            echo   "[$data] "
            export   TTT= "$data "
        fi
done   <   data.txt
----------------------

运行方式:
.   test.sh
前面加一个点表示在当前shell进程运行,这样可以修改当前环境变量

*******************************************************************

*******************************************************************

*******************************************************************

*******************************************************************

shell读文件的十二种方法(收藏)Shell 2009-11-03 22:52:53 阅读503 评论1 字号:大中小
#!/usr/bin/ksh

#

# SCRIPT: 12_ways_to_parse.ksh.ksh

#

#

# REV: 1.2.A

#

# PURPOSE:  This script shows the different ways of reading

#       a file line by line.  Again there is not just one way

#       to read a file line by line and some are faster than

#       others and some are more intuitive than others.

#

# REV LIST:

#

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值