shell
来源:互联网 发布:杨颖同款秀禾服淘宝 编辑:程序博客网 时间:2024/04/29 22:49
1、写入文件:
echo "ABC" > test1
一个文件写到另一个文件:
cat file1 > file2
创建一个空文本:
方法1:
touch file1
方法2:
> file2
方法3
ecto "" > file3
方法4:
cat /dev/null >$filename
2、替换文件里的内容
//*****************choice_wifilink.sh:
read line < essidname &&
sed "s/ylst-s/$line/" /etc/wpa_supplicant.conf > tempfile &&//替换
cat tempfile > /etc/wpa_supplicant.conf &&
rm -f tempfile &&
read line < essidkey &&
sed "s/beacon506/$line/" /etc/wpa_supplicant.conf > tempfile &&//替换
cat tempfile > /etc/wpa_supplicant.conf &&
rm -f tempfile
//***************essidname
ylst-s
//***************essidkey
beacon506
//***************/etc/wpa_supplicant.conf
ctrl_interface=/var/run/wpa_supplicant
update_config=1
network={
ssid="ylst-s"
psk="beacon506"
#key_mgmt=WPA-PSK
}
有一个连接http://zhidao.baidu.com/question/533549408.html
方法1:
sed -i 's/被替换的内容/要替换成的内容/' file
方法2:
sed 's/被替换的内容/要替换成的内容/g' file > file.out
mv file.out file
不能这样做:
sed 's/被替换的内容/要替换成的内容/g' file > file
这样只会清空源文件。
3、一行行读取文件内容
#!/bin/bash
cat test | while read line
do
echo $line
done
有个文件size,内容为
12
236
25
跟test的内容
db_09_11.tgz
db_09_12.tgz
db_09_13.tgz
一一对应
在我读出test的内容后也对应读出size的内容
paste size test | while read line;do echo $line;done
- shell
- shell
- shell
- shell
- shell
- Shell
- shell
- Shell
- shell
- shell
- SHELL
- Shell
- shell
- shell
- shell
- shell
- shell
- shell
- nio是什么
- 值得mark的11个开源机器学习项目
- C++学习 C++纯虚类
- 报风险网站做301重定向的后果
- <context:spring-configured/> 的作用
- shell
- 【原创】一些正则表达式
- Binary Tree Level Order Traversal II
- 工业水处理:威立雅锅炉给水处理技术解析
- 仙境传说OX答题器
- mysql遇到error1045或2003
- Project Eluer - 19
- 使用jdbc驱动连接oracle数据库
- 全排列