Redian新闻
>
how to extract data every 20 lines.
avatar
how to extract data every 20 lines.# Unix - 噫吁兮,危乎高哉
x*i
1
I have a data file with 20000 lines. Let me named it as A.dat
But I don't need so many lines of data to draw graph.
I just hope I can extract data from A.dat every 200 lines
and generate a new data file named B.dat and use file B.dat
to do my post-processing job.
Is there any shell command which can implement this job easily?
Thanks for help!
avatar
i*n
2
awk 'NR%20==0 {print $0}' A.dat > B.dat

【在 x***i 的大作中提到】
: I have a data file with 20000 lines. Let me named it as A.dat
: But I don't need so many lines of data to draw graph.
: I just hope I can extract data from A.dat every 200 lines
: and generate a new data file named B.dat and use file B.dat
: to do my post-processing job.
: Is there any shell command which can implement this job easily?
: Thanks for help!

avatar
x*i
3
You are the man! :)
I used script as follows:
lineno=1
while read line
do
lineno=`expr $lineno + 1 `
rest=`expr $lineno % 20`
if [ $rest = 0 ]
then
echo $line
fi
done
echo $lineno
But it executed so slow and it can not work under linux!
By the way, can you use 'sed' command to do it? I am not familiar with
awk....

【在 i*******n 的大作中提到】
: awk 'NR%20==0 {print $0}' A.dat > B.dat
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。