[英]How to download the contents of a web page on to a .txt file using wget in Linux command line?
[英]Is it possible to compare 2 contents of same line in .txt file using linux?
假設我在文本文件中有以下內容
input.txt
aaa bbb
ccc ddd
我想將用戶輸入與文本文件中的內容進行比較。
假設提示用戶輸入 2 個字符串,如果第一個字符串與文本文件中的內容匹配(比如說 aaa,這是第 1 行的第一個內容) ,我應該如何修改我的代碼以使程序比較第二個字符串用戶在同一行輸入了第二個內容(bbb) ?
echo "First input: "; read input1
echo "Second input: "; read input2
if [ "$input1" = $(< input.txt) ]; then
# content matches
else
# content doesn't match
fi
從input.txt
中讀取第一行:
read -r shouldbe_input1 shouldbe_input2 < <(head -n1 input.txt)
然后只是比較:
if [ "$input1" = "$shouldbe_input1" ] && [ "$input2" = "$shouldbe_input2" ]; then
echo yay
else
echo not yay
菲
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.