shell 按行讀取並儲存成陣列
從ip.txt裡讀取IP.然後把IP地址賦值到一個數組裡.
IP檔案如下:
Address: 220.181.26.163
Address: 220.181.26.174
Address: 220.181.26.175
Address: 220.181.26.176
Address: 220.181.19.228
Address: 220.181.19.229
Address: 220.181.26.161
Address: 220.181.26.162
Shell程式碼
方法一:
for x in ` awk '{print $2}' ip.txt `
{
echo $x
}
方法二:
ARRAY=($(awk '{print $2}' ip.txt))
方法三:
n=0;while read a b;do array[$n]=$b;((n++));done<ip.txt
方法四:
n=1
while ((n<=$(cat ip.txt|wc -l)))
do
ipaddr[$n]=$(cat ip.txt|sed -n "${n}p"|awk '{print $2}')
((n+=1))
done
n=`expr $n - 1`
相關推薦
shell 按行讀取並儲存成陣列
從ip.txt裡讀取IP.然後把IP地址賦值到一個數組裡. IP檔案如下: Address: 220.181.26.163 Address: 220.181.26.174 Address: 220.181.26.175 Address: 220.181.26.176 Address: 220.181
php從爬蟲爬取的txt檔案按行讀取並寫入儲存到excel,csv中
需求:採集攜程網酒店資訊步驟: 使用火車頭編寫採集規則並儲存到txt檔案 編寫php指令碼讀取txt檔案並按照規則儲存到csv程式碼:<?php /** * 讀取txt檔案,存入csv表格
python按行讀取並替換
tracking 技術分享 view popu tag sdn -c hat con fp = open(‘‘test2.txt‘,‘w‘) #打開你要寫得文件test2.txt lines = open(‘test1.txt‘).readlines() #
Python之按行讀取DataFrame二維陣列資料
import numpy as np import pandas as pd data = {"省份":['北京', "上海", "天津", "重慶", "江蘇", "浙江", "廣東"], "年份":[2017, 2015, 2013, 2016, 200
shell 按行讀取文件的內容
echo bsp compile status odin pan div true mpi test.py: #coding=utf-8 import subprocess compilePopen = subprocess.Popen(‘gcc haha‘
shell按行從檔案讀取, 分割成陣列
cut -d 如果找不到分割符號, 就會輸出原字串,無聊-f後面是什麼,加-s就什麼都不輸出了 #!/bin/bash # 從檔案中按行讀取,每行分割成字串, 形成陣列# j=0 while read line do i=1 while : do
java按行讀取並存到陣列(轉換成任意型別)(演算法題目常用)
做用java做演算法時,需要進行.txt檔案的讀寫問題。 思考:現在知道如何用讀每行的資料的,怎麼把他們分開? //從檔案中讀取 File inFile=new File("E:\\input.txt"); BufferedReader br=new BufferedR
shell指令碼按行讀取檔案並解析
shell指令碼讀取一個配置檔案,配置檔案的格式如下: name=abc pwd=123456 permission=mop 檔名稱為 config.cfg 要在shell腳本里讀取這個配置檔案,並且把值一一賦給相應的變數,實現如下 while read l
利用反射和泛型把Model對象按行儲存進數據庫以及按行取出然後轉換成Model 類實例 MVC網站通用配置項管理
serve 取數 sele oid 數據庫操作 comm 評論 data http 利用反射和泛型把Model對象按行儲存進數據庫以及按行取出然後轉換成Model 類實例 MVC網站通用配置項管理 2018-3-10 15:18 | 發布:Admin | 分類:代碼庫
java按行讀取檔案並對檔案進行加密和解密
package com.alibaba.datax.plugin.reader.selfxmlfilereader.util; import java.io.UnsupportedEncodingException; import java.security
Opencv—讀取視訊/通過手機攝像頭捕捉視訊並儲存成視訊流
1.獲取下載好的視訊並播放視訊 import cv2#引入cv2模組 #設定視訊捕獲 capture = cv2.VideoCapture('0.wmv')#0.wmv表示同一資料夾目錄下的視訊名 while True: ret, frame = capture.read()#變數ret
QT和VS讀取.txt檔案中的資料並儲存為陣列
QT中讀取.txt檔案並儲存為陣列 QFile fpx("/work/qt_workspace/saly/pix_x.txt"); QFile fpy("/work/qt_workspace/saly/pix_y.txt"); // QVector&l
shell指令碼-----按行讀取檔案
[email protected]:5.read-line$ cat file.bin hello world this is 1 this is 2 this is 3[email protected]:5.read-line$ ./read-line.sh file.bin ###
Java按行讀取檔案並輸出
public class ReadFileByLines { public static void main(String[] args) { try{ //1.開啟一個file
NIO按行讀取檔案內容,並打印出來
package com.broada.wssh.groovy; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.nio.ByteBuf
Go1.9按行讀取日誌檔案並處理
package main import ( "bufio" "bytes" "context" "log" "os" "sync" ) const (
C#將TextBox裡資料按行讀取到陣列中
TextBox多行輸入: 將屬性中Multiline設定為Truestring[] str = new string[TextBox1.Lines.Length];for (int i = 0; i < TextBox1.Lines.Length; i++){ s
Java 按行讀取檔案按行寫入檔案並以空格分割字串
首先是按行讀取字串 import java.io.BufferedReader; import java.io.File; import java.io.FileReader; public c
按行讀取String類型
類型 char logs ont log read pan nbsp span BufferedReader br = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(content.ge
python 按行讀取判斷是否為空
span logs bsp 判斷 [0 mat adl () exce 1 for line in fr.readlines(): 2 try: 3 # print(len(line)) 4