ChinaUnix.net
相关文章推荐:

getline(stdin) segmentation

cat aa 1 2 3 4 5 6 awk '{getline d; print d}' aa 2 4 6 awk 'BEGIN{getline d; print d}' aa 1 第二种方法,为什么只打印了一个1

by tt_yy123 - Shell - 2012-03-22 20:38:17 阅读(1418) 回复(8)

相关讨论

cat file01 abcd1234 bb334 ccddpp0098 a222 c how to split the file01 : abcd bb ccddpp a c awk 'BEGIN{"cat file01"| getline var;split(var,a, );print a[1]}' hehe, NO separator !

by addictlinux - Shell - 2009-05-21 15:46:46 阅读(1552) 回复(7)

今天写一个小程序,统计一下一个文件中以'P'开头的行数。我用了两种方法,一种是使用sed,另一种是用c,使用了getline函数。这个函数的声明如下: #define _GNU_SOURCE #include stdio.h> ssize_t getline(char **lineptr, size_t *n, FILE *stream); 说明如下: getline() reads an entire line, storing the address of the buffer containing the text into *lineptr. The buffer is null-terminated ...

by redoc - Linux文档专区 - 2007-01-04 21:32:01 阅读(2669) 回复(0)

大家好: 我的脚本中有stdin,但它影响perl命令行用>输出。具体如下,我的脚本名是calculation.pl[code]#!/usr/bin/perl print "use dilution factor?[y/n] "; $answer = <stdin>; chomp $answer; if ($answer eq 'y'){$dil_fac = 10} elsif ($answer eq 'n'){$dil_fac = 1} else {print STDERR "use dilution factor? please notify by typing y or n"; exit} ... 脚本内容 ... [/code]但是,当我运行 perl calculation.pl > ou...

by pony2001mx - Perl - 2014-06-14 18:27:18 阅读(2971) 回复(3)

这是我在网上看到的一句话: “stdin stdout 和 stderr 关联的整数形式的文件描述符分别是 0,1 还有 2。预处理器符号 stdin_FILENO,STDOUT_FILENO 和 STDERR_FILENO 分别以它们为值” 我在程序中,用0替代stdin_FILENO是可以的,但用0替代stdin 就不行了,程序segmentation Fault (core dumped) 请教???

by zhongf1114 - C/C++ - 2007-05-11 16:19:58 阅读(3289) 回复(8)

[root@localhost ~]# cat b Name Age Height Weight anger 18 173 74 liusan 20 177 80 aojun 24 167 49 tianjing 30 179 75 haobo 28 171 65 有个文本b 我想打印包含Name这行的下一行 只有一行 用下面个脚本和我预期不一样,求解 #!/bin/awk $1 ~ /Name/ { getline print $0} 实际结果 [root@localhost ~]# awk -f a b Name Age Height Weight anger ...

by 123freebird - Shell - 2012-03-06 11:05:20 阅读(2795) 回复(6)

如题,getline可以获取命令行执行结果,如:[code]awk 'BEGIN { "echo abc"|getline a1; "echo def"|getline a2; "echo 123"|getline a3; printf "a1=[%s] a2=[%s] a3=[%s]\n",a1,a2,a3;}'[/code]结果:[code]a1=[abc] a2=[def] a3=[123][/code]但是如果其中任意两次命令一样,则getline无法获取结果:[code]awk 'BEGIN { "echo abc"|getline a1; "echo def"|getline a2; "echo abc"|getline a3; printf "a1=[%s] a2=[%s] a3=[%s]\...

by ruifox - Shell - 2011-02-15 17:16:54 阅读(2016) 回复(6)

本帖最后由 jiajuzh 于 2010-11-30 10:46 编辑 数据如下 aaa 1 2 3 4 5 6 bbb aaa 1 2 3 4 5 7 bbb aaa 1 2 3 4 5 6 ccc 1 2 3 4 5 6 处理规则:如果第六列为6,则打印此行及此行相临的上下一行;awk实现方法如下 awk '{if($6!~/6/){tmp=$0}if($6~/6/){getline s;print tmp,$0,s}}' 思路为:如果第六列不匹配6保存为tmp,如果匹配读取下一行,并打印tmp,当前行及下一行 但是这样设计存在一个问题,就是如果当前行的第6列...

by jiajuzh - Shell - 2011-10-05 09:46:59 阅读(3553) 回复(9)

$:cat test1,输出如下: abc xyz 123 dir cd 然后我就 cat test1 | awk '{ getline ; print }',输出如下: xyz dir cd 不明白为什么省略了 abc和123 ,高人来

by xwmhmily - Shell - 2008-07-22 10:34:09 阅读(2594) 回复(10)

输入awk -f exchange.awk temp.dat #exchange.awk: { if ((getline tmp) > 0) { print tmp print $0 } else print $0 } #temp.dat: wan tew free phore 期望输出: tew wan phore free 实际输出: tew phore 输出的是偶数行,相当于做了两次next,请大家帮忙看看,谢过了先!

by eadgbeguitar - Shell - 2008-03-13 20:34:44 阅读(1574) 回复(5)

#include #include using namespace std; int main(void) { ifstream in("/home/zx/oldfile"); ofstream out("/home/zx/newfile"); string s; while (getline(in,s)) out<

by ancientlegend - C/C++ - 2006-05-16 12:02:46 阅读(1429) 回复(6)