如何使用bash从多个文件的每一行删除前n个字符?
我有大量的出口产品。所有文件都具有相同的结构。我需要从同一目录中每个文件的第一行中删除前15个字符 我试过这首曲子,但它删除了每行的前15个字符:如何使用bash从多个文件的每一行删除前n个字符?,bash,sed,Bash,Sed,我有大量的出口产品。所有文件都具有相同的结构。我需要从同一目录中每个文件的第一行中删除前15个字符 我试过这首曲子,但它删除了每行的前15个字符: #!/bin/bash for file in *.json do sed 's/^.\{15\}//' "$file" > "$file".new mv "$file".new "$file" done 这行代码如下所示: "dashboard": { 我想让这行以{.开头,试试这个: #!/bin/bash for
#!/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
试试这个:
#!/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
案例不一样。替换和删除不是相同的术语。我编辑了我的原始评论。案例不一样。替换和删除不是相同的术语。我编辑了我的原始评论。或者只编辑了
sed-I'1s/*/{/'.*.json
。可能sed-I'1c{'*.json
。或者只编辑了sed-I'1s/*/{/'*.json
。可能sed-i'1c{'*.json
。