我理解这个问题可能会重复,但我并没有得到我正在寻找的东西。所以,这是我的必需品。我想匹配两个文件之间的第1列,并将file2.txt的第4列追加到file1.txt。如果列不匹配,我想将“0”作为最后一个字段追加到file1.txt
我直接从NSE网站上获取了两个文件。
file1.txt 的数据如下所示:
20MICRONS,20170207,41.4,41.75,40.75,40.95,74624
3IINFOTECH,20170207,5.5,5.65,5.5,5.6,2679590
3MINDIA,20170207,11865.7,11919.95,11632.05,11892.25,425
等等。这是我的主文件,因此应该保留file1.txt中的所有行。
file2.txt 的数据如下所示:
20MICRONS,EQ,57597,77.18
3IINFOTECH,EQ,1795693,67.01
依旧......
请注意,该文件可能不包含相同数量的行。
我的输出文件可能如下,
20MICRONS,20170207,41.4,41.75,40.75,40.95,74624,77.18
3IINFOTECH,20170207,5.5,5.65,5.5,5.6,2679590,67.01
3MINDIA,20170207,11865.7,11919.95,11632.05,11892.25,425,0
我试过了,
awk -F, 'NR==FNR{a[$1]=$0; next} {print a[$1]","$4}' file1.txt file2.txt
但没有将整行的file1.txt作为输出。
答案 0 :(得分:0)
这样的事情应该有效(假设第1列中的条目在两个文件中只出现一次):
DELIMITER //
Drop PROCEDURE IF EXISTS GetRecord;
CREATE PROCEDURE GetRecord(IN hr int,IN TableName varchar(50))
BEGIN
declare done int DEFAULT 0;
declare ID int DEFAULT 0;
declare name varchar(25);
declare cur1 cursor for SELECT id ,name FROM TableName;
declare continue handler for not found set done=1;
SET @query = concat('update Student set no=no+? where id=?');
PREPARE stmt from @query;
open cur1;
igmLoop: loop
fetch cur1 into ID,name;
SELECT ID;
IF done = 1 THEN
LEAVE igmLoop;
END IF;
SET @id = ID;
SET @HR =hr;
EXECUTE stmt USING @HR,@id;
end loop igmLoop;
close cur1;
DEALLOCATE PREPARE stmt;
END;//
DELIMITER ;
答案 1 :(得分:0)
您可以使用 df %>%
gather(variable, value, vac, dac) %>%
ggplot(aes(x = id
, y = value
, color = factor(app)
, linetype = variable
, group = paste(app, variable))) +
geom_line()
:
join
如果文件未按开始排序,则必须将它们排序为:
join -a 1 -e 0 -t ',' -j 1 -o '1.1 1.2 1.3 1.4 1.5 1.6 1.7 2.4' file1 file2