0

For example, I've a text file having following lines (no. 423 and 424):

    //printf("%d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\n",i,c1,c2,c3,c11,c12,c21,c22,c31,c32); //testcells
    printf("%d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d   \n",i,r1,r2,r3,r11,r22,r33,r44,r55,r66,r77,r88,r99); //testnodes

Now, suppose I want to remove // in the 423th line i.e characters of column 5 and 6 form 423th line. And simultaneously, suppose I want to add // in 424th line in columns 5 and 6 such that expected output should be

    printf("%d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\n",i,c1,c2,c3,c11,c12,c21,c22,c31,c32); //testcells
    //printf("%d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d   \n",i,r1,r2,r3,r11,r22,r33,r44,r55,r66,r77,r88,r99); //testnodes

How do I do that? (preferably with sed or awk)

1 Answer 1

3

One way:

sed -e '423s!//!!; 424s!printf!//&!' < input > output

This assumes that the first // on line 423 is the one you want to remove, and that it's the printf on line 424 that you want to comment out.

To specifically update based on the columns:

sed -e '423s!^\(....\)//!\1!; 424s!^\(....\)!\1//!' < input > output
0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.