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