将变量传递给sed for while循环 [英] Passing variable to sed for while loop

查看:88
本文介绍了将变量传递给sed for while循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用shell sed循环从第n行开始的文件,我可以使它适用于整数(下面的例子从第5行开始),但是我想用sys参数变量替换该整数: linesToBegin = $ 1

I want to loop over a file starting from the n th line using shell sed,I could make it work for an integer (example below starting from line 5), but I want to replace the integer by an sys argument variable : linesToBegin= $1

这是代码:

sed -n '5,$ p' twitter_ids.txt | while read linecontent
do
            echo $linecontent 
done

当我用linesToBegin替换数字5时:

When I replace the number 5 by linesToBegin:

sed -n '$linesToBegin,$ p' twitter_ids.txt | while read linecontent

我说一个错误

sed: -e expression #1, char 3: extra characters after comman

推荐答案

linesToBegin="$1"
sed -n "$linesToBegin,\$ p" twitter_ids.txt | while read linecontent
do
            echo "$linecontent"
done

现在应该可以工作了.只需双引号即可.

Should probably work now. Just need double quotes.

这篇关于将变量传递给sed for while循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆