`

Read write text file in shell

 
阅读更多
#!/bin/bash
contains() {
    string="$1"
    substring="$2"
    if test "${string#*$substring}" != "$string"
    then
        return 0    # $substring is in $string
    else
        return 1    # $substring is not in $string
    fi
}


file=$1
dest=$2
rm $dest
while IFS= read -r line
do
        # display $line or do somthing with $line
        echo "$line" >> "$dest"


        contains "$line" ",ABC," && echo $line | sed -e "s/,ABC,/,ZRM,/g" >> "$dest"
       
done <"$file"

 

分享到:
评论

相关推荐

    Pro.Bash.Programming.Scripting.the.GNULinux.Shell.2nd.Edition

    Pro Bash Programming teaches you how to effectively utilize the Bash shell in your programming. The Bash shell is a complete programming language, not merely a glue to combine external Linux commands....

    Senfore_DragDrop_v4.1

    A batch file, convert_forms_to delphi_4_format.bat, is supplied in the demo directory which automates the conversion process. The C++ Builder demo forms are distributed in binary format. 7) If ...

    Python Cookbook英文版

    6.3 Allowing Multithreaded Read Access While Maintaining a Write Lock 6.4 Running Functions in the Future 6.5 Synchronizing All Methods in an Object 6.6 Capturing the Output and Error Streams ...

    2009 达内Unix学习笔记

    其中,1是执行权(Execute),2是写权限(Write),4是读权限(Read), 具体权限相当于三种权限的数相加,如7=1+2+4,即拥有读写和执行权。 另外,临时文件/目录的权限为rwt,可写却不可删,关机后自动删除;建临时目录...

    go系统编程(英文版)

    how to read and write records from files, and how to lock files in Go. Chapter 7, Working with System Files, teaches you how to deal with Unix system files, which includes writing data to Unix log ...

    C#学习的101个经典例子

    Data Access - Read and Write Images from a Database Data Access - Retreive and Process data with a SQL Data Reader Data Access - Sort and Filter with a DataView Data Access - Use ADO 2.6 Data Access -...

    drupal 6.12

    The files directory created in step 4 is the default file system path used to store all uploaded files, as well as some temporary files created by Drupal. After installation, the settings for the ...

    fk:Fahrenheit和Kelvin-跨平台Shell命令

    (write file) selfup@win42 MINGW64 ~ /go/src/github.com/selfup/fk (master) $ fk wr foo/bar/example.txt " hello world " 0775 (file exists) selfup@win42 MINGW64 ~ /go/src/github.com/selfup/fk (master) $ ...

    shelmet:Shell开机以使用文件系统并运行子进程命令

    说明文件: : PyPI: ://pypi.python.org/pypi/shelmet/ Github动作: : 特征运行并定义子流程命令run cmd 与文件互动atomicdfile atomicdir read , readchunks , readlines , readtext , readbytes write ...

    Mask 98 for PRwin98

    FILE_ID.DIZ ZIP file description in standard BBS format. Note: You are not allowed to distribute the PRWIN98.INI configuration file if it contains registered user details. However, please feel free ...

    RealThinClientSDK_v610_BETA

    instances in the "ShellScript" line and you should add the path to the RTC SDK Lib folder directly after each "-Fu/Developer/Embarcadero/fmi" instance. For example, if you have made the complete RTC...

    Small.Sharp.Software.Tools.epub

    Turn tedious chores into quick tasks: read and write files, manage complex directory hierarchies, perform network diagnostics, download files, work with APIs, and combine individual programs to ...

    ICSharpCode.SharpZipLib.dll

    ZipInputStream s = new ZipInputStream(File.OpenRead(file)); ZipEntry theEntry; while ((theEntry = s.GetNextEntry()) != null) { string directoryName = Path.GetDirectoryName(theEntry.Name); string...

    Android SELinux 快速处理工具 log2allow

    linux 64位操作系统,处理android selinux配置时快速处理方案 ...allow XXXXX_shell init:file { add_name append create execute execute_no_trans getattr map open read remove_name search unlink write };

    VB编程资源大全(英文控件)

    PicOpener.zip PicOpener is an ActiveX control that allows you to read image files in over 50 formats and convert them to BMP bitmaps&lt;END&gt;&lt;br&gt;20,PicConverter.zip Read over 50 and write 15 image ...

    MS-DOS 5.0

    In this file the following topics are covered: 1. Introduction 2. Solving Setup Problems 2.1 Priam and Everex Hard Disks 2.2 SyQuest Removable Hard Disk 2.3 Bernoulli Drive 2.4 Disk Manager 2.5...

    UNIX环境高级编程(第二版,英文版)

    Examples in the Text Systems Used to Test the Examples Acknowledgments Chapter 1. UNIX System Overview Section 1.1. Introduction Section 1.2. UNIX Architecture ...

    8.1 android 串口编程

    allow system_app serial_device:chr_file { open read write ioctl getattr }; allow system_app proc_stat:file { getattr }; 这样那些自己驱动里创建的设备节点也就可以访问了。 然后mmm sepolicy。 串口的操作...

    ipmitool for windows版.zip

    命令行:raw Send a RAW IPMI request and print responsei2c Send an I2C Master Write-Read command and print responselan Configure LAN Channelschassis Get chassis status and set...

Global site tag (gtag.js) - Google Analytics