我有一大堆文件。
AcademicCapIcon.svelte ArrowSmLeftIcon.svelte CalculatorIcon.svelte
AdjustmentsIcon.svelte ArrowSmRightIcon.svelte CalendarIcon.svelte
...
...所有文件都有相同的格式。例如,AcademicCapIcon.svelte有以下内容:
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" aria-hidden="true">
<path d="M12 14l9-5-9-5-9 5 9 5z"/>
<path d="M12 14l6.16-3.422a12.083 12.083 0 01.665 6.479A11.952 11.952 0 0012 20.055a11.952 11.952 0 00-6.824-2.998 12.078 12.078 0 01.665-6.479L12 14z"/>
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 14l9-5-9-5-9 5 9 5zm0 0l6.16-3.422a12.083 12.083 0 01.665 6.479A11.952 11.952 0 0012 20.055a11.952 11.952 0 00-6.824-2.998 12.078 12.078 0 01.665-6.479L12 14zm-4 6v-7.5l4-2.222"/>
</svg>我想在每个文件的开头插入以下内容。
<script>
export let className = "h-6 w-6";
</script>并在class={className}后插入xmlns="http://www.w3.org/2000/svg"。
例如,上述AcademicCapIcon.svelte文件的最终结果将是:
<script>
export let className = "h-6 w-6";
</script>
<svg xmlns="http://www.w3.org/2000/svg" class={className} fill="none" viewBox="0 0 24 24" stroke="currentColor" aria-hidden="true">
<path d="M12 14l9-5-9-5-9 5 9 5z"/>
<path d="M12 14l6.16-3.422a12.083 12.083 0 01.665 6.479A11.952 11.952 0 0012 20.055a11.952 11.952 0 00-6.824-2.998 12.078 12.078 0 01.665-6.479L12 14z"/>
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 14l9-5-9-5-9 5 9 5zm0 0l6.16-3.422a12.083 12.083 0 01.665 6.479A11.952 11.952 0 0012 20.055a11.952 11.952 0 00-6.824-2.998 12.078 12.078 0 01.665-6.479L12 14zm-4 6v-7.5l4-2.222"/>
</svg>如何使用终端或Bash脚本完成此操作?
发布于 2022-02-06 08:33:13
将插入内容放入自己的文件中,然后尝试
sed 's|xmlns="http://www.w3.org/2000/svg"|& class={className}| ' insert_file orig_file
<script>
export let className = "h-6 w-6";
</script>
<svg xmlns="http://www.w3.org/2000/svg" class={className} fill="none" viewBox="0 0 24 24" stroke="currentColor" aria-hidden="true">
.
.
.
</svg>https://unix.stackexchange.com/questions/689494
复制相似问题