I've been looking everywhere. Didn't find the answer so I'm looking up to you!
Program in my job outputs many 10-50 *.pc files with folder-structure:
RESULTS/MODEL_Y0/Positioning_1.pc
RESULTS/MODEL_Y0/SK312_2SK_Y0_2012.pc
RESULTS/MODEL_Y100/Positioning_2.pc
RESULTS/MODEL_Y100/SK312_2SK_Y100_2012.pc
RESULTS/MODEL_Y250/Positioning_45.pc
RESULTS/MODEL_Y250/SK312_2SK_-Y575_2012.pc
Each PC file has inside absolute paths starting on xxx (not always 101, but it's always the second occurance of the INCLU word) line like:
INCLU / Positioning_1.pc
INCLU / /ST/statika/AGP-Pedestrian_Ansa-Meta/SK312_2SK_xxx/SK312_SERIE.inc
INCLU / /ST/statika/AGP-Pedestrian_Ansa-Meta/SK312_2SK_xxx/SK312_xPL_impactor.inc
INCLU / /ST/statika/AGP-Pedestrian_Ansa-Meta/SK312_2SK_xxx/SK312_materials.inc
I need to change these lines of absolute path to relative like:
INCLU / Positioning_1.pc
INCLU / ../../SK312_SERIE.inc
INCLU / ../../SK312_xPL_impactor.inc
INCLU / ../../SK312_materials.inc
Which I've done by writing a script placed above RESULTS folder: (part of the script)
grep -rl "${SEARCH}" --include \*.pc ./ | xargs sed -i "s#${SEARCH}#${REPLACE}#g"
where:
$SEARCH = /ST/statika/AGP-Pedestrian_Ansa-Meta/SK312_2SK_xxx/
$REPLACE = ../../
BUT here is the problem. When operating from longer than 81 chars path, the program will output the .pc files in the same folder-structure pattern, but inside the PC file, the absolute paths are separated to new line by - on 81. char position:
INCLU / Positioning_1.pc
INCLU / /ST/statika/uziv/JVERNER/PROJEKTY/Ansa/AGP-Pedestrian_Ansa-Meta/SK312_2S-
K_xxx/SK312_SERIE.inc
INCLU / /ST/statika/uziv/JVERNER/PROJEKTY/Ansa/AGP-Pedestrian_Ansa-Meta/SK312_2S-
K_xxx/SK312_xPL_impactor.inc
INCLU / /ST/statika/uziv/JVERNER/PROJEKTY/Ansa/AGP-Pedestrian_Ansa-Meta/SK312_2S-
K_xxx/SK312_materials.inc
where:
$SEARCH = /ST/statika/uziv/JVERNER/PROJEKTY/Ansa/AGP-Pedestrian_Ansa-Meta/SK312_2SK_xxx/
Here's the problem. My script doesn't see the variable $SEARCH. What's even bigger problem is that the path could be longer than 180 chars so there will be three-line path with two - dividers.
I can't comprehend how to write a script that would be functional with these multi-lines so that the path variable would shorten to ../../SK312_*.inc as before with short absolute one-line path.
INCLU, second after the-at random position of the absolute path after the 81th minus "INCLU / " so after 73th char of the path./ST/statika/uziv/JVERNER/PROJEKTY/Ansa/AGP-Pedestrian_Ansa-Meta/SK312_2SK_xxx/SK312_SERIE.incwas split to 2 lines:/ST/statika/uziv/JVERNER/PROJEKTY/Ansa/AGP-Pedestrian_Ansa-Meta/SK312_2S-&K_xxx/SK312_SERIE.incIn thePCfile the 81 char line is:INCLU / /ST/statika/uziv/JVERNER/PROJEKTY/Ansa/AGP-Pedestrian_Ansa-Meta/SK312_2S-(with theINCLU /)PCfiles relative on the working directory. 1st kind - with lines less than 81 chars long:INCLU / /ST/statika/AGP-Pedestrian_Ansa-Meta/SK312_2SK_xxx/SK312_SERIE.incand the 2nd kind - with lines longer than 81 chars long separated into two lines and divided by-on the 81st char of the first line. I have to use Linux: OpenSuse 12.2 and every tool that is installed by default. My script has to work on all computers in my company.