Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ################# FANUC CNC-FILE SPLITTER ########################
- #
- # CNC-FILE-SPLITTER FOR FANUC PROGRAM-OUTPUT-FILES
- # COMPATIBLE WITH LINUX, ANDROID & WINDOWS WSL
- # THIS FUNCTION EXTRACTS ALL PROGRAMS FROM A CNC OUTPUT FILE
- # TESTED WITH VERSION 0i,16i,18i-TB,31i
- # FOR EASY-USE, ADD THIS CODE AS FUNCTION IN YOUR ~/.bashrc
- # AND START WITH COMMAND
- #
- # fanuc_split
- #
- # CODED: SEBASTIAN STAITSCH
- # LAST EDIT: 2021/12/21 @ 15:19 - Version 3.1
- # MAIL: [email protected]
- # VIDEO: https://youtu.be/ChFv7KmzxHI
- #
- ##################################################################
- fanuc_split(){
- loop(){
- echo -e --- "\e[32mFOUND\e[0m" $(egrep -no '^O{1}[0-9]{1,}|^<' $file | wc -l) Programs in $file
- sleep 2
- sed -i '1d' $file
- sed -i 's/\r//g' $file
- while [ "$(cat $file | wc -l)" -gt 1 ]; do
- name=$(egrep -o -m1 '^<{1}\S*>{1}|^O[0-9]{1,}' $file | tr -d '<>')
- start=$(egrep -no -m1 '^O{1}[0-9]{1,}|^<' $file | grep -Po '^.*:' | tr -d ':')
- end=$(egrep -no -m2 '^O{1}[0-9]{1,}|^<|^%' $file | grep -Po '^.*:' | tr -d ':' | tail -n1)
- (( end-- ))
- echo "%" > cnc_$folder/$name
- sed -n ''$start','$end'p' $file >> cnc_$folder/$name
- sed -n 2,3p cnc_$folder/$name
- echo
- echo "%" >> cnc_$folder/$name
- sed -E -i 's/\s$//' cnc_$folder/$name
- (( end-- ))
- sed -i '1,'$end'd' $file
- done
- rm $file
- mv $file.BAK $file
- }
- echo
- echo "Welcome to Fanuc-File-Splitter v3.1 - Coded by Sebastian Staitsch"
- echo " Contact: [email protected]"
- echo
- sleep 1
- echo
- for file in `ls *`; do
- if [[ "$(grep -E -c '^O[0-9]{4,}|^<.+>$' $file)" -gt 1 ]]; then
- cp $file $file.BAK
- folder=$(echo $file | sed 's/.ALL// ; s/.TXT//')
- mkdir cnc_$folder
- loop
- else
- echo -e --- File $file "\e[1;31;40mnot compatible\e[0m"
- sleep 1
- fi
- done
- echo
- echo -e "\e[1;33;40m--- Success\e[0m"
- } 2>/dev/null
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement