① linux下C++讀取文件去重的問題
#include<fstream>
#include<vector>
#include<string>
#include<algorithm>
#include<iostream>
#include<sstream>
classdata_t{
public:
data_t():val(5){}
std::string&operator[](intconsti){
returnval[i];
}
std::stringconst&operator[](intconsti)const{
returnval[i];
}
private:
std::vector<std::string>val;
};
template<inti>
structcmp1{//用於sort函數
booloperator()(data_tconst&a,data_tconst&b)const{
returna[i]<b[i];
}
};
template<inti>
structcmp2{//用於unique函數
booloperator()(data_tconst&a,data_tconst&b)const{
returna[i]==b[i];
}
};
intmain(){
std::ifstreamistr("input.txt");
if(!istr){
std::cerr<<"文件打開失敗 ";
return__LINE__;
}
typedefstd::vector<data_t>vector_t;
vector_tdata;
//讀取文件
std::stringline;
intline_num=0;
while(getline(istr,line)){
++line_num;
data_ttmp_data;
std::istringstreamtmp_str(line);
inti=0;
for(;i!=5;++i){
if(!getline(tmp_str,tmp_data[i],' ')){
std::cerr<<"在第"<<line_num<<"行發生錯誤 ";
}
}
if(i==5){//該行讀取成功
data.push_back(tmp_data);
}
}
//按關鍵字1去重
std::sort(data.begin(),data.end(),cmp1<0>());
vector_t::iteratorlast=std::unique(data.begin(),data.end(),cmp2<0>());
//按關鍵字2去重
std::sort(data.begin(),last,cmp1<1>());
last=std::unique(data.begin(),last,cmp2<1>());
data.erase(last,data.end());
//輸出到另一個文件
std::ofstreamostr("output.txt");
if(!ostr){
std::cerr<<"文件打開失敗 ";
return__LINE__;
}
for(inti=0;i!=data.size();++i){
for(intj=0;j!=5;++j){
ostr<<data[i][j]<<" ";
}
ostr<<" ";
}
return0;
}
輸入文件為input.txt,樣例:
111222333444555
111222333444555
1111222333444555
1111222333444555
11111222333444555
11111222333444555
輸出到output.txt,樣例:
111222333444555
② Linux裡面sort -M file3命令作用是什麼
Linux中sort命令的功能說明,如下所示;
sort命令功能:
排序文件並輸出,
sort命令既可以對特定文件進行排序輸出,也可以從stdin中獲取輸入
sort命令的語法格式:
sort [參數] [文件]
-------參數說明-----
-b:忽略每行前面開始出的空格字元
-c:檢查文件是否已經按照順序排序
-d:排序時,處理英文字母、數字及空格字元外,忽略其他的字元
-f:排序時,將小寫字母視為大寫字母
-i:排序時,除了040至176之間的ASCII字元外,忽略其他的字元
-m:將幾個排序號的文件進行合並
-M:將前面3個字母依照月份的縮寫進行排序
-n:依照數值的大小排序
-o:將排序後的結果存入制定的文件
-r:以相反的順序來排序
-t:指定排序時所用的欄位分隔字元
-k:指定需要排序的欄位
例:
sort命令 的示例分享
[root@******* c]# cat t.c
#include
#include
#include
int main(){undefined
char c;
while(Read(0,&c,1) !=0)
Write(1,&c,1);
return 0;
}
[root@******* c]# sort t.c
}
char c;
#include
#include
#include
int main(){undefined
return 0;
while(Read(0,&c,1) !=0)
Write(1,&c,1);
③ linux下的UUID是個什麼東西
UUID
簡介
UUID含義是通用唯一識別碼 (Universally Unique Identifier),這 是一個軟體建構的標准,也是被開源軟體基金會 (Open Software Foundation, OSF) 的組織應用在分布式計算環境 (Distributed Computing Environment, DCE) 領域的一部分。
2作用
UUID 的目的,是讓分布式系統中的所有元素,都能有唯一的辨識資訊,而不需要透過中央控制端來做辨識資訊的指定。如此一來,每個人都可以建立不與其它人沖突的 UUID。在這樣的情況下,就不需考慮資料庫建立時的名稱重復問題。目前最廣泛應用的 UUID,即是微軟的 Microsoft's Globally Unique Identifiers (GUIDs),而其他重要的應用,則有 Linux ext2/ext3 檔案系統、LUKS 加密分割區、GNOME、KDE、Mac OS X 等等。
3組成
UUID是指在一台機器上生成的數字,它保證對在同一時空中的所有機器都是唯一的。通常平台會提供生成的API。按照開放軟體基金會(OSF)制定的標准計算,用到了乙太網卡地址、納秒級時間、晶元ID碼和許多可能的數字
UUID由以下幾部分的組合:
(1)當前日期和時間,UUID的第一個部分與時間有關,如果你在生成一個UUID之後,過幾秒又生成一個UUID,則第一個部分不同,其餘相同。
(2)時鍾序列。
(3)全局唯一的IEEE機器識別號,如果有網卡,從網卡MAC地址獲得,沒有網卡以其他方式獲得。
UUID的唯一缺陷在於生成的結果串會比較長。關於UUID這個標准使用最普遍的是微軟的GUID(Globals Unique Identifiers)。在ColdFusion中可以用CreateUUID()函數很簡單地生成UUID,其格式為:xxxxxxxx-xxxx- xxxx-xxxxxxxxxxxxxxxx(8-4-4-16),其中每個 x 是 0-9 或 a-f 范圍內的一個十六進制的數字。而標準的UUID格式為:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx (8-4-4-4-12),可以從cflib 下載CreateGUID() UDF進行轉換。
4應用
使用UUID的好處在分布式的軟體系統中(比如:DCE/RPC, COM+,CORBA)就能體現出來,它能保證每個節點所生成的標識都不會重復,並且隨著WEB服務等整合技術的發展,UUID的優勢將更加明顯。根據使用的特定機制,UUID不僅需要保證是彼此不相同的,或者最少也是與公元3400年之前其他任何生成的通用唯一標識符有非常大的區別。
通用唯一標識符還可以用來指向大多數的可能的物體。微軟和其他一些軟體公司都傾向使用全球唯一標識符(GUID),這也是通用唯一標識符的一種類型,可用來指向組建對象模塊對象和其他的軟體組件。第一個通用唯一標識符是在網路計算機系統(NCS)中創建,並且隨後成為開放軟體基金會(OSF)的分布式計算環境(DCE)的組件。
④ 關於linux 命令 uniq. 怎麼樣才能做到以下結果。
cat unique.txt |sort|uniq
sort是先進行排序
uniq 然後刪除文件中的重復行
⑤ linux中每個存儲器都有一個唯一什麼
應該是UUID
⑥ linux文件行排序去重結果不同sort和uniq
騷年,你有仔細觀察者兩個命令嗎?
舉個例子:
文件filea為:
a
b
c
c
d
b
執行sort filea |uniq -u |wc -l,先排序,則刪除了c和b的行;
執行sort -u filea |wc -l,排序,同時刪除相同的行,則只刪除c行。
⑦ 如何設置linux系統賬戶許可權可讀寫
默認的是許可權是777可讀可寫可執行。
你可以改一下配置文件
FTP服務啟動後,文件/etc/ftpusers中配置的用戶是不允許使用FTP服務的,如果需要使用,請將該用戶名前加「#」取消限制。你說的ABC可以用,別的不能用,那麼就在ABC這個賬號前加個#就OK了
⑧ linux 中文件有uuid嗎
linux中有UUID,保存在文件/sys/class/dmi/id/proct_uuid中,可以使用cat等命令查看,如:
sudocat/sys/class/dmi/id/proct_uuid
UUID說明:
UUID是指在一台機器上生成的數字,它保證對在同一時空中的所有機器都是唯一的。通常平台會提供生成的API。按照開放軟體基金會(OSF)制定的標准計算,用到了乙太網卡地址、納秒級時間、晶元ID碼和許多可能的數字。
UUID由以下幾部分的組合:
(1)當前日期和時間,UUID的第一個部分與時間有關,如果你在生成一個UUID之後,過幾秒又生成一個UUID,則第一個部分不同,其餘相同。
(2)時鍾序列。
(3)全局唯一的IEEE機器識別號,如果有網卡,從網卡MAC地址獲得,沒有網卡以其他方式獲得。
UUID的唯一缺陷在於生成的結果串會比較長。關於UUID這個標准使用最普遍的是微軟的GUID(Globals Unique Identifiers)。在ColdFusion中可以用CreateUUID()函數很簡單地生成UUID,其格式為:xxxxxxxx-xxxx- xxxx-xxxxxxxxxxxxxxxx(8-4-4-16),其中每個 x 是 0-9 或 a-f 范圍內的一個十六進制的數字。而標準的UUID格式為:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx (8-4-4-4-12),可以從cflib 下載CreateGUID() UDF進行轉換。
⑨ linux UUID是什麼
UUID是設備唯一識別碼,在掛載等的時候,是可以直接用UUID的,等同於相應的設備及設備編號
⑩ linux下怎麼樣設置ssh無密碼登錄
1.Linux下生成密鑰
ssh-keygen的命令手冊,通過」man ssh-keygen「命令:
通過命令」ssh-keygen -t rsa「
生成之後會在用戶的根目錄生成一個 「.ssh」的文件夾
進入「.ssh」會生成以下幾個文件
authorized_keys:存放遠程免密登錄的公鑰,主要通過這個文件記錄多台機器的公鑰
id_rsa : 生成的私鑰文件
id_rsa.pub :生成的公鑰文件
know_hosts : 已知的主機公鑰清單
如果希望ssh公鑰生效需滿足至少下面兩個條件:
1) .ssh目錄的許可權必須是700
2) .ssh/authorized_keys文件許可權必須是600
2.遠程免密登錄
原理圖:
常用以下幾種方法:
2.1 通過ssh--id的方式
命令: ssh--id -i ~/.ssh/id_rsa.put <romte_ip>
舉例:
[root@test .ssh]# ssh--id -i ~/.ssh/id_rsa.pub 192.168.91.135
[email protected]'s password:
Now try logging into the machine, with "ssh '192.168.91.135'", andcheck in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
[root@test .ssh]# ssh [email protected]
Last login: Mon Oct 10 01:25:49 2016 from 192.168.91.133
[root@localhost ~]#
常見錯誤:
[root@test ~]# ssh--id -i~/.ssh/id_rsa.pub 192.168.91.135
-bash: ssh--id: command not found //提示命令不存在
解決辦法:yum -y installopenssh-clients
2.2通過scp將內容寫到對方的文件中
命令:scp -p~/.ssh/id_rsa.pub root@<remote_ip>:/root/.ssh/authorized_keys
舉例:
[root@test .ssh]# scp -p ~/.ssh/[email protected]:/root/.ssh/authorized_keys
[email protected]'s password:
id_rsa.pub 100% 408 0.4KB/s 00:00
[root@test .ssh]#
[root@test .ssh]#
[root@test .ssh]#
[root@test .ssh]# ssh [email protected]
Last login: Mon Oct 10 01:27:02 2016 from 192.168.91.133
[root@localhost ~]#
也可以分為兩步操作:
$ scp ~/.ssh/id_rsa.pubroot@<remote_ip>:pub_key //將文件拷貝至遠程伺服器
$ cat ~/pub_key>>~/.ssh/authorized_keys //將內容追加到authorized_keys文件中,不過要登錄遠程伺服器來執行這條命令
2.3 通過Ansible實現批量免密
2.3.1 將需要做免密操作的機器hosts添加到/etc/ansible/hosts下:
[Avoid close]
192.168.91.132
192.168.91.133
192.168.91.134
2.3.2 執行命令進行免密操作
ansible<groupname> -m authorized_key -a "user=root key='{{lookup('file','/root/.ssh/id_rsa.pub') }}'" -k
示例:
[root@test sshpass-1.05]# ansible test -m authorized_key -a"user=root key='{{ lookup('file','/root/.ssh/id_rsa.pub') }}'" -k
SSH password: ----->輸入密碼
192.168.91.135 | success >> {
"changed": true,
"key": "ssh-rsa 7A3izwT3///18B6FV5moE/8yTbFA4dBQahdtVP +sODbtGPC34HMGAHjFlsC/SJffLuT/ug/== [email protected]",
"key_options": null,
"keyfile": "/root/.ssh/authorized_keys",
"manage_dir": true,
"path": null,
"state": "present",
"unique": false,
"user": "root"
}
[root@test sshpass-1.05]#
2.4 手工復制粘貼的方式
將本地id_rsa.pub文件的內容拷貝至遠程伺服器的~/.ssh/authorized_keys文件中