Hello friends,
Thanks very much for the support. Sorry for the confusion.
Explaining the situation with a sample case
Input is a sample text containing a
if block as follows
HTML Code:
10 20 30 40
1 * * * * 50 Columns- just assume
1 statements .......
2 if ( condition
3 )
4 {
5 Statement 1;
6 Statement 2;
7 Statement 3;
8 }
9 statements ..............
10
10 20 30 40
1 * * * * 50 Columns- just assume
I would like to do the following with the help of a script
1. Bring the
Closing bracket of if statement from LINE 3 to to end of LINE 2
as follows
HTML Code:
10 20 30 40
1 * * * * 50 Columns- just assume
1 statements .......
2 if ( condition )
3
10 20 30 40
1 * * * * 50 Columns- just assume
2. In LINE 7 move the closing brace of if block from column 10 to say column 20 as follows (updated line numbers since the last operation removed a line) such that the "if" & "{" starts from same column.
HTML Code:
10 20 30 40
1 * * * * 50 Columns- just assume
5 Statement 2;
6 Statement 3;
7 }
8 statements ..............
10 20 30 40
1 * * * * 50 Columns- just assume
3. In LINE 3 move the opening brace of if block from say column 20 to end of LINE 2 as follows. (Note that the statements below should move upwards as the LINE 3 & 4 got removed.)
HTML Code:
10 20 30 40
1 * * * * 50 Columns- just assume
1 statements .......
2 if ( condition ) {
3 Statement 1;
10 20 30 40
1 * * * * 50 Columns- just assume
4. From LINE 3 to LINE 7. The Statement 1 & Statement 3 should align according to position (say, column 23) of Statement 2 as follows. And Add a new line after Statement 3 & before Statement 1.
HTML Code:
10 20 30 40
1 * * * * 50 Columns- just assume
3
4 Statement 1;
5 Statement 2;
6 Statement 3;
7
10 20 30 40
1 * * * * 50 Columns- just assume
After all the above operation the final
if block should look like this (properly aligned & spaced)
HTML Code:
10 20 30 40
1 * * * * 50 Columns- just assume
1 statements .......
2 if ( condition ) {
3
4 Statement 1;
5 Statement 2;
6 Statement 3;
7
8 }
9 statements ..............
10
10 20 30 40
1 * * * * 50 Columns- just assume
I need a script that is just not meant for a
if loop but for any situation which is why i used samples containing AAA, BAA.
<space> meant tab space, i am a beginner & just got comfortable with sed & awk...well, i am ready to have keys to the new doors..so please do provide any new or better methods to solve the problem.
Summary
If possible it will be nice if i can get a script, that can do the following. so that i can have a start.
1. finds the position of the first word in a line.
>for example the script should be able to tell me the position of A in A11 BBB CC1
2. finds the position of the last word in a line (calculating 1st character position of the first word of a line)
> for example the script should be able to tell me the position of '2' in B11 DDD ZZ2 (calculating last character position of the last word of a line)
3. A script that can move any word say B11 to a position after CC1 (line to line movement)
4. A script that can move any word say RRR such that the A11 & RRR should start from same column (column to column movement)
HTML Code:
Before
A11 BBB CC1
B11 DDD ZZ2
RRR FFF
After
A11 BBB CC1 B11
DDD ZZ2
RRR FFF
Awaiting for support. Thanks