1

I have big number of exports. All files have same structure. I need to remove first 15 characters from each first line in each file in the same directory.

I tried this piece but this removed first 15 characters from every line:

#!/bin/bash

for file in *.json
do
    sed 's/^.\{15\}//' "$file" > "$file".new
    mv "$file".new "$file"
done

The line looks like this:

  "dashboard": {

and I want the line to start with { .

Astr0o
  • 15
  • 4
  • Cases there are not the same. Replacement and deletion are not the same terms. I've edited my original comment. – Astr0o May 22 '19 at 16:00

1 Answers1

0

try this:

#!/bin/bash
for file in ./*.json; do
   sed -i '1s/.*/{/' "$file"
done

explanation

# 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
UtLox
  • 3,744
  • 2
  • 10
  • 13