1

From a text file, I want to remove the first 6 columns. I tried sed as follows, but I have to do it six times (one for each column). Is there any efficient way to do it (or pass the 6 columns at once for sed)?

sed -i -r 's/(\s+)?\S+//1' file

Thanks!

Adam Majdi
  • 75
  • 1
  • 1
  • 11

1 Answers1

0

You could do this within regex and quantifying braces if a column consists of non-whitespace characters with optional leading spaces:

sed -i -r 's/^((\s+)?\S+){6} *//' file
revo
  • 45,845
  • 14
  • 70
  • 113
  • 1
    I suggest to replace `{6}/` with `{6} /` to remove a leading white space. – Cyrus Apr 15 '18 at 16:48
  • @downvoter, I'd appreciate an explanation for your downvote. I may either improve or remove the answer. – revo Apr 15 '18 at 17:41