Delete first N char from a text file

Issue

I have large data file with some data as :

01 01 00 2c 00 82 03 00 02 00 00 00 07 08 07 08   
07 08 07 08 07 08 07 08 07 08 07 08 07 08 07 08   
07 08 07 08 07 08 07 08 07 08 07 08 07 08 07 08   
07 08 07 08 07 08 07 08 07 08 07 08 07 08 07 08   
0f 08 08 08 0a 08 07 08 0f 08 08 08 08 08 08 08   
08 08 08 08 08 07 08 07 0a 07 07 07 0f 07 08 07   
08 07 08 07 08 07 08 07 08 07 08 07 0a 07 07 07   
..
..... 

I would like to delete every first n characters from every 6th row

I have found a command :

sed 's/^.\{,n\}//' file

But this command deletes first n chars from each row, which I do not want to happen.

Could someone suggest the right command?

Solution

awk -v n=17 '(NR%6)==1 { print substr($0, n+1); next } 1' file

The condition uses modulo arithmetic on the line number NR to select every sixth line, starting from the first. The final 1 causes the other lines to be printed normally.

You haven’t revealed the value of n so I guessed.

Answered By – tripleee

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published