linuxshell读取文件
A. linux shell 读取一个配置文件并获取其中的全部内容,急!!!!!!!
con=`cat profile|awk '{printf $0}' `
profile是你的配置文件名,这个是把所有内容存到con中。如果要加分隔符号的话,在printf中加就行,不过要注意用双引号引起来
B. Linux shell编程如何不解压读取gz压缩的文本
直接读取 一个gz压缩文件的方法:
直接创建了一个内容:"asdfasdfasfd" 的 1.txt文件并用gzip 压缩。
读取:$ zcat 1.txt.gz asdfasdfasfd。
如果内容过长可以接 less 查看:$ zcat 1.txt.gz | less。
C. linux shell读取文件每一行加入用户输入
cat是读取文件里面的内容,read读到的是文本的
用户输入,直接 read即可
比如 read passwd,用户输入的就可用$passwd调用
你的脚本很乱,记得搞清楚你到底要实现什么
D. linux shell 脚本里 怎么用 cat 命令 读取 一个文件的内容 然后用 sed命令 替换
sed
-i
s/zhengshu/"`cat
ca.crt`"/g
xl.sql
就可以了,只要ca.crt里面没有/字符也没有换行就可以了。
E. Linux中的sh命令的详细解释
linxu下的sh命令相当于是shell命令语言的解释器。下面由我为大家整理了linux的sh命令的详细解释的相关知识,希望对大家有帮助!
一、Linux中的sh命令的详细解释
sh命令是shell命令语言解释器,执行命令从标准输入读取或从一个文件中读取。通过用户输入命令,和内核进行沟通!Bourne Again Shell (即bash)是自由软件基金会(GNU)开发的一个Shell,它是Linux系统中一个默认的Shell。Bash不但与Bourne Shell兼容,还继承了C Shell、Korn Shell等优点。
语法
bash [options] [file]
选项
-c string:命令从-c后的字符串读取。
-i:实现脚本交互。
-n:进行shell脚本的语法检查。
-x:实现shell脚本逐条语句的跟踪。
二、Linux中的sh命令的具体例子
使用-x选项跟踪脚本调试shell脚本,能打印出所执行的每一行命令以及当前状态:
[root@AY1307311912260196fcZ satools]# sh -x check_ssh_login.sh
+ DEFINE=30
+ cat /var/log/secure
+ awk '/Failed/ {++ip[$(NF-3)]} END {for (i in ip) print i"="ip[i]}'
++ cat /root/satools/black.txt
+ for i in '`cat /root/satools/black.txt`'
++ echo 121.42.0.16=1427
++ awk -F= '{print $1}' + IP=121.42.0.16
++ echo 121.42.0.16=1427
++ awk -F= '{print $2}'
+ NUM=1427
+ '[' 1427 -gt 30 ']'
+ grep 121.42.0.16 /etc/hosts.deny
+ '[' 1 -gt 0 ']'
+ echo sshd:121.42.0.16
+ echo vsftpd:121.42.0.16
+ for i in '`cat /root/satools/black.txt`'
++ echo 121.42.0.72=276
++ awk -F= '{print $1}'
+ IP=121.42.0.72
++ awk -F= '{print $2}'
++ echo 121.42.0.72=276
+ NUM=276 + '[' 276 -gt 30 ']'
+ grep 121.42.0.72 /etc/hosts.deny
+ '[' 1 -gt 0 ']'
+ echo sshd:121.42.0.72
+ echo vsftpd:121.42.0.72
三、Linux中对.sh文件的操作命令
1、创建test.sh文件
touch test.sh
2、编辑sh文件
vi test.sh
3、保存退出
敲击esc, 然后输入 :wq ,回车退出
4、添加可执行权限,当然默认就是可执行的。
chmod +x test.sh
5、运行文件
(1)./test.sh
(2)sh test.sh
6、删除文件
rm test.sh
F. 如何用shell获取linux目录下的文件名
获取所有常规文件的文件名并打印出来的脚本listfile.sh如下
#!/bin/bash
dir="/*"
dir=$1$dir
for f in $dir
do
if [ -f $f ]
then
echo $f
fi
done
使用方法:
$ listfile.sh PATH
原理:
PATH参数是路径,将路径后加上“/*”,代表该目录下的所有文件和目录名,利用for循环比较每个文件是否是常规文件( -f比较运算符),若if表达式为真则打印
举例:
ls -l
total 36
-rwxrwxr-x 1 lipeng lipeng 48 Nov 29 20:08 aaa.sh
drwxrwxr-x 2 lipeng lipeng 4096 May 4 2015 byteorder
drwxrwxr-x 8 lipeng lipeng 4096 May 3 2015 hello
-rwxrwxr-x 1 lipeng lipeng 122 Nov 29 20:16 listfile.sh
-rw-rw-r-- 1 lipeng lipeng 177 Aug 1 03:10 main.cpp
drwxrwxr-x 2 lipeng lipeng 4096 Sep 13 16:42 matrix
drwxrwxr-x 5 lipeng lipeng 4096 Apr 28 2015 modbus
drwxrwxr-x 2 lipeng lipeng 4096 Sep 13 10:10 shtest
drwxrwxr-x 2 lipeng lipeng 4096 Sep 16 18:21 test
$ ./listfile.sh .
./aaa.sh
./listfile.sh
./main.cpp
G. Linux shell 读取文本中某几行数据并输出成新文件
# for file in `ls abc*.xml`;do sed -n -e '1,10p'宴茄 -e '晌盯察50,60p' $file >则举 ${file}_new;done
H. linux shell 如何读取文件特定位置的数据
题主你好,
测试所用的文本文件t1内容如下:
=====
希望可以帮到题主, 欢迎追问.
I. Linux shell编程如何不解压读取gz压缩的文本
直接腔脊读取 一个gz压缩文件:x0dx0ax0dx0a我直接创建了一个内容:"asdfasdfasfd" 的 1.txt文件并用gzip 压缩。x0dx0a读取:x0dx0a$ zcat 1.txt.gz x0dx0aasdfasdfasfdx0dx0a如果内容过长可以接 less 查看伍掘渗散衫:x0dx0a$ zcat 1.txt.gz | less