sed,引号中的正斜杠 [英] sed, foward slash in quotes

查看:27
本文介绍了sed,引号中的正斜杠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 sedbash 中做一些被证明非常困难的事情.

I'm trying to do something in bash with sed that is proving to be extremely difficult.

我有一个 bash 脚本,它的第一个参数是日期.

I have a bash script that takes as its first argument a date.

代码想要更改文本文件中的一行以包含传递的日期.这是代码

The code want to change a line in a text file to include the passed date. Here's the code

#!/bin/bash

cq_fname="%let outputfile="/user/cq_"$1".csv";"

sed "29s/.*/"$ct_fname"/" file1.sas > file2.sas

此脚本在第三行失败,我得到了有关乱码命令的信息.有没有人知道一个聪明的方法来让它工作?如何在 sed 中的引号中获得正斜杠?

This script fails on the third line, I get something about a garbled command. Does anybody know a clever way to get this to work? How can I get a forward slash in quotes in sed?

推荐答案

您可以使用任何字符代替 /,所以只选择一个不在 $ct_fname:

You can use any character in place of the /, so just pick one that is not in $ct_fname:

sed "29s|.*|"$ct_fname"|" file1.sas > file2.sas

这篇关于sed,引号中的正斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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