I have a text file of a bunch of constants in Java format:
What I'd like to do is produce a file with all the numbers changed to the line number minus 1, like so:
My Google-fu is weak today, and my brain can't make sense of the Google search results. I'm sure there's a way to do this with awk, sed, perl, or some other UNIXy commands, but I cannot figure out how. Help? 
EDIT: Just found a solution. awk to the rescue!
... does exactly what I want.
Code:
public static final int CONSTANT_ZIPPY = 3;
public static final int CONSTANT_FOO = 0;
public static final int CONSTANT_BAR = 1;
public static final int CONSTANT_BAZ = 2;
Code:
public static final int CONSTANT_ZIPPY = 0;
public static final int CONSTANT_FOO = 1;
public static final int CONSTANT_BAR = 2;
public static final int CONSTANT_BAZ = 3;
EDIT: Just found a solution. awk to the rescue!
Code:
awk '/[0-9]*/ {print $1 " " $2 " " $3 " " $4 " " $5 " " $6 " " FNR - 1 ";"}' filename.txt
Last edited: