Moving lines within a txt file

A newbie to shell scripting.....

I need some assistance in doing the following:

I have a system generated text file(a makefile basically).

Before I can execute the make command, I need to modify one section of this generated file.

The generated section is as follows:

# INCLUDE macro for SCI
#~~~~~~~~~~~~~~~~~~~~~~~
XYZ_MAIN_INCLUDE = \
-I/Path_1 \
-I/Path_2 \
-I/Path_3 \
-I/Path_4

Basically, Path_4 has be placed at the start of the INCLUDE section with appropriate changes to new line delimiters.

This modified section should look as follows:

# INCLUDE macro for SCI
#~~~~~~~~~~~~~~~~~~~~~~~
XYZ_MAIN_INCLUDE = \
-I/Path_4 \
-I/Path_1 \
-I/Path_2 \
-I/Path_3

I have to make similar changes to 6 different files in 6 different locations in the directory structure before I can execute make.

Can I achieve this using a shell script without having to modify all the files manually everytime I need to execute a make?

Thanks in advance for any suggestions.

show exact sample of the make file if possible

Thank you ghostdog74 for your response.

Not sure if I can post the contents of the entire makefile here:

The section that needs manual editing(with line numbers enabled) looks like this:

66	\# INCLUDE macro for SCI
67	\#~~~~~~~~~~~~~~~~~~~~~~~
68	CDIPOSIX\_MAIN_INCLUDE = \\
69		-I/dev/adapt\_layer/s9cdi/CDIPosix/Posix_Main \\
70		-I/dev/adapt\_layer/s9cdi/CDIPosix/Posix_Main/inc \\
71		-I/dev/adapt_layer/s9cdi/CDIInitialisation/Initialization \\
72		-I/dev/adapt_layer/s9cdi/CDIPosix \\
73		-I/dev/adapt\_layer/s9cdi/CDIPosix/PCK_CDIPosix \\
74		-I/gplus3/source/range/os20/include 

The same section after manual editing looks like this:

66	\# INCLUDE macro for SCI
67	\#~~~~~~~~~~~~~~~~~~~~~~~
68	CDIPOSIX\_MAIN_INCLUDE = \\
69		-I/gplus3/source/range/os20/include \\
70		-I/dev/adapt\_layer/s9cdi/CDIPosix/Posix_Main \\
71		-I/dev/adapt\_layer/s9cdi/CDIPosix/Posix_Main/inc \\
72		-I/dev/adapt_layer/s9cdi/CDIInitialisation/Initialization \\
73		-I/dev/adapt_layer/s9cdi/CDIPosix \\
74		-I/dev/adapt\_layer/s9cdi/CDIPosix/PCK_CDIPosix

FYI, this section appears in between the same line numbers always. Does this information help?

Thanks

awk 'FNR==NR{$1="";a[FNR]=$0;next}   
   FNR==4{print $1" "a[9];next}   
   FNR==9{print $1" " a[4]}
   FNR<9{print}   
' "file" "file"

output:

# ./test.sh
66 # INCLUDE macro for SCI
67 #~~~~~~~~~~~~~~~~~~~~~~~
68 CDIPOSIX_MAIN_INCLUDE = \
69  -I/gplus3/source/range/os20/include
70 -I/dev/adapt_layer/s9cdi/CDIPosix/Posix_Main/inc \
71 -I/dev/adapt_layer/s9cdi/CDIInitialisation/Initialization \
72 -I/dev/adapt_layer/s9cdi/CDIPosix \
73 -I/dev/adapt_layer/s9cdi/CDIPosix/PCK_CDIPosix \
74  -I/dev/adapt_layer/s9cdi/CDIPosix/Posix_Main \

not sure is it what you want.

Thank you ghostdog74 for your reply.

Yes from the output this is what I want....but......

As I mentioned earlier, I have 6 files(a.mak, b.mak.....f.mak) in various locations in the directory structure, the contents of which needs to be similarly modified before I can invoke make.

Assuming I provide the location/paths of all 6 files somewhere in this script, will this script make modifications as above and save the files or is that too much to ask for?

if you can do it on one file, you can do it on many files (of the same type). just need to do some scripting ..