我有大量的导出。所有文件都具有相同的结构。我需要从同一目录中每个文件的每个第一行中删除前15个字符。
我尝试了这篇文章,但这删除了每行的前15个字符:
#!/bin/bash
for file in *.json
do
sed 's/^.\{15\}//' "$file" > "$file".new
mv "$file".new "$file"
done
这条线看起来像这样:
"dashboard": {
我希望这一行以{开头。
试试这个:
#!/bin/bash
for file in ./*.json; do
sed -i '1s/.*/{/' "$file"
done
解释
# loop over all *.json files in current directory
for file in ./*.json; do
# -i use inplace replacement
# replace first line with '{'
sed -i '1s/.*/{/' "$file"
done