1

I have multiple files which have too many characters in the first line. I would line to trim the first line only after n characters. the characters to remove after different in every file and the characters before those to be removed. The rest of the lines of the file I need to remain unchanged.

For example

123456789123456789
important
important
important

will become

123456789
important
important
important

I have got this so far:

for i in *.txt; do sed -r 's/(.{10}).*/\1/' $i; done 

but this trims all the lines, I only want to trim the first line and I cant figure out how to make it only apply to line 1.

αғsнιη
  • 41,407
cats123
  • 17
  • This is not what I mean. I know to use sed but I cant figure out how to only use it on the first line. for i in .txt; do sed -r 's/(.{10})./\1/' $i; done I was using but this removes from all the lines. I need to only edit the first. – cats123 Aug 23 '21 at 17:33
  • 1
    thanks for showing your research! I retracted my downvote and upvoted. if you continue another search for "replace first line only" as said, you can resolve your question by yourself – αғsнιη Aug 23 '21 at 17:42
  • I didnt realise this, thanks! I promise I did my research but I really havent found anything – cats123 Aug 23 '21 at 17:44
  • @cats123 use `for i in .txt; do sed -r '1s/(.{10})./\1/' $i; done not the '1' before the s to apply only to line 1. – icarus Aug 23 '21 at 18:59

0 Answers0