Cari dan Replace String
find . -type f -exec sed -i ‘s/\/css/css/g’ {} +
Perintah diatas find . -type f
adalah perintah untuk mencari file dengan hanya mencari file tanpa directory.
Sedangkan perintah sed -i 's/\/css/css/g'
diatas untuk mencari string /css
untuk di-replace dengan string css
, atau menghapus backslash
pada string /css
.
Praktek FIND dan SED dalam bash_script
Berikut contoh bash script untuk mencari beberap string yang akan di-replace dengan string lainnya :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/bin/bash
echo -e "Start to Copy......"
cp -r ../abuisa.github.io/_site/ ./
echo -e "Copy \t\t\t : Copy Success......"
echo -e "Start to Clear......"
find _site/ -type f -exec sed -i 's/\/css/css/g' {} + # Replace string
echo -e "css \t\t\t : Clear....."
find _site/ -type f -exec sed -i 's/https:\/\/abuisa.github.io\///g' {} + # Replace string
echo -e "remove hostname 1 \t : Clear....."
find _site/ -type f -exec sed -i 's/http:\/\/0.0.0.0:4000\///g' {} + # Replace string
echo -e "remove hostname 2 \t : Clear....."
find _site/ -type f -exec sed -i 's/"\/categories"/"categories.html"/g' {} + # Replace string
echo -e "categories \t\t : Clear....."
find _site/ -type f -exec sed -i 's/"\/linkcolection"/"linkcolection.html"/g' {} + # Replace string
echo -e "linkcolection \t\t : Clear....."
find _site/ -type f -exec sed -i 's/"\/penelitian"/"penelitian.html"/g' {} + # Replace string
echo -e "penelitian \t\t : Clear....."
find _site/ -type f -exec sed -i 's/"\/me"/"me.html"/g' {} + # Replace string
echo -e "me \t\t\t : Clear....."
find _site/ -type f -exec sed -i 's/src="\/js/src="js/g' {} + # Replace string
echo -e "Js \t\t\t : Clear....."
rm .fuse_hidden00*
echo -e "Remove .fuse_hidden00* \t : Clear....."
echo -e "Clear Finished !..."
Buat setiap halaman web ini dapat di akses OFFLINE
Copy folder _site
ke lokal komputer, contoh taruh di /home/user/Download/web_ini/_site
Copy Script diatas dan simpan dalam bentuk file dengan nama web_to_offline.sh
, letakkan file ini di folder web_ini
Jalankan script dari terminal dengan perintah ./web_to_offline.sh
kemudian Enter.
Seletelah selesai, halaman sudah bisa diakses dengan tampilah yang sama sebagaimana Online.
Script Versi 1.1 :
Versi 1.1 dibawah diupload pada 22,12,2017.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
echo -e "Start to Copy......"
if cp -ru ../abuisa.github.io/_site/ ./
then
#notify-send "Copy Data Suksess" -i info
echo -e "Copy \t\t\t : OK, Copy Success......"
else
echo -e "Copy \t\t\t : GAGAL Copy !"
fi
echo -e "Start to Clear......"
if find _site/* .html -type f -exec sed -i 's/\/css/css/g' {} + # Replace string
then
echo -e "css \t\t\t : OK, Clear....."
else
echo -e "css \t\t\t : GAGAL Clear !"
fi
if find _site/* .html -type f -exec sed -i 's/https:\/\/abuisa.github.io\///g' {} + # Replace string
then
echo -e "remove hostname 1 \t : OK, Clear....."
else
echo -e "remove hostname 1 \t : GAGAL Clear !"
fi
if find _site/* .html -type f -exec sed -i 's/http:\/\/0.0.0.0:4000\///g' {} + # Replace string
then
echo -e "remove hostname 2 \t : OK, Clear....."
else
echo -e "remove hostname 2 \t : GAGAL Clear !"
fi
if find _site/* .html -type f -exec sed -i 's/"\/categories"/"categories.html"/g' {} + # Replace string
then
echo -e "categories \t\t : OK, Clear....."
else
echo -e "categories \t\t : GAGAL Clear !"
fi
if find _site/* .html -type f -exec sed -i 's/"\/linkcolection"/"linkcolection.html"/g' {} + # Replace string
then
echo -e "linkcolection \t\t : OK, Clear....."
else
echo -e "linkcolection \t\t : GAGAL Clear !"
fi
if find _site/* .html -type f -exec sed -i 's/"\/penelitian"/"penelitian.html"/g' {} + # Replace string
then
echo -e "penelitian \t\t : OK, Clear....."
else
echo -e "penelitian \t\t : GAGAL Clear !"
fi
if find _site/* .html -type f -exec sed -i 's/"\/me"/"me.html"/g' {} + # Replace string
then
echo -e "me \t\t\t : OK, Clear....."
else
echo -e "me \t\t\t : GAGAL Clear !"
fi
if find _site/* .html -type f -exec sed -i 's/src="\/js/src="js/g' {} + # Replace string
then
echo -e "Js \t\t\t : OK, Clear....."
else
echo -e "Js \t\t\t : GAGAL Clear !"
fi
ix = $( find . -name ".fuse_hidden00*" |wc -l ) ;
if [ " $ix " == "0" ]
then
echo -e "Remove .fuse_hidden00* \t : GAGAL, File Not Found !"
else
echo "Aada "
if rm .fuse_hidden00*
then
echo -e "Remove .fuse_hidden00* \t : OK, Clear....."
fi
fi
if [ $1
pt = $( zenity --entry --title = "Copyt File" --text = "Input Destination Path : " ) ;
if sudo cp -rfu _site/ " $pt "
then
echo -e "Copy \t\t\t : OK, Copy to ' $pt ' Success......"
else
echo -e "Copy \t\t\t : GAGAL Copy to ' $pt ' !"
fi
echo -e "Clear Finished !..."
##--- Dengan menampilkan Notifikasi di layar desktop ---
notify-send "Selesai On_Web to Off_Web !" -i text-x-script
zenity --display :0 --info --width = 150 --height = 100 --title "BackUp Finished !" --text "Selesai Menyalin Web_on To Web_Off" # OK,
Script Versi 1.2 :
Versi 1.2 dibawah diupload pada 25,12,2017.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/bin/bash
echo -e "Start to Copy......"
if cp -rf ../abuisa.github.io/_site/ ./
then echo -e "Copy \t\t\t : OK, Copy Success......"
else echo -e "Copy \t\t\t : GAGAL Copy !"
fi
echo -e "Start to Clear......"
if find _site/* .html -type f -exec sed -i 's/\/css/css/g' {} + # Replace string
then echo -e "css \t\t\t : OK, Clear....."
else echo -e "css \t\t\t : GAGAL Clear !"
fi
if sed -i 's/<li><a href="https:\/\/abuisa.github.io\//<li><a href="/g' _site/categories.html
then echo -e "categories 1 \t\t : OK, Clear....."
else echo -e "categories 1 \t\t : GAGAL Clear !"
fi
if sed -i 's/<li><a href="http:\/\/0.0.0.0:4000\//<li><a href="/g' _site/categories.html
then echo -e "categories 2 \t\t : OK, Clear....."
else echo -e "categories 2 \t\t : GAGAL Clear !"
fi
if find _site/* .html -type f -exec sed -i 's/https:\/\/abuisa.github.io\//index.html/g' {} + # Replace string
then echo -e "remove hostname 1 \t : OK, Clear....."
else echo -e "remove hostname 1 \t : GAGAL Clear !"
fi
if find _site/* .html -type f -exec sed -i 's/http:\/\/0.0.0.0:4000\//index.html/g' {} + # Replace string
then echo -e "remove hostname 2 \t : OK, Clear....."
else echo -e "remove hostname 2 \t : GAGAL Clear !"
fi
if find _site/* .html -type f -exec sed -i 's/"\/categories"/"categories.html"/g' {} + # Replace string
then echo -e "categories \t\t : OK, Clear....."
else echo -e "categories \t\t : GAGAL Clear !"
fi
if find _site/* .html -type f -exec sed -i 's/"\/linkcolection"/"linkcolection.html"/g' {} + # Replace string
then echo -e "linkcolection \t\t : OK, Clear....."
else echo -e "linkcolection \t\t : GAGAL Clear !"
fi
if find _site/* .html -type f -exec sed -i 's/"\/penelitian"/"penelitian.html"/g' {} + # Replace string
then echo -e "penelitian \t\t : OK, Clear....."
else echo -e "penelitian \t\t : GAGAL Clear !"
fi
if find _site/* .html -type f -exec sed -i 's/"\/me"/"me.html"/g' {} + # Replace string
then echo -e "me \t\t\t : OK, Clear....."
else echo -e "me \t\t\t : GAGAL Clear !"
fi
if find _site/* .html -type f -exec sed -i 's/src="\/js/src="js/g' {} + # Replace string
then echo -e "Js \t\t\t : OK, Clear....."
else echo -e "Js \t\t\t : GAGAL Clear !"
fi
if find _site/* -type f -name 'index.html' |xargs sed -i 's/<h2><a href="\//<h2><a href="/g'
then echo -e "Index.html \t\t : OK, Clear....."
else echo -e "Index.html \t\t : GAGAL Clear !"
fi
if find _site/* -type f -name 'index.html' |xargs sed -i 's/<a href="\/page/<a href="page/g'
then echo -e "Page \t\t\t : OK, Clear....."
else echo -e "Page \t\t\t : GAGAL Clear !"
fi
if find _site/page* -type f -name 'index.html' |xargs sed -i 's/src="\/js\/main.js"/src="..\/js\/main.js"/g'
then echo -e "Page header 1 \t\t : OK, Clear....."
else echo -e "Page header 1 \t\t : GAGAL Clear !"
fi
if find _site/page* -type f -name 'index.html' |xargs sed -i 's/src="js\/jquery.min.js/src="..\/js\/jquery.min.js/g'
then echo -e "Page header 2 \t\t : OK, Clear....."
else echo -e "Page header 2 \t\t : GAGAL Clear !"
fi
if find _site/page* -type f -name 'index.html' |xargs sed -i 's/src="js\/hijricalendar-kuwaiti.js/src="..\/js\/hijricalendar-kuwaiti.js/g'
then echo -e "Page header 3 \t\t : OK, Clear....."
else echo -e "Page header 3 \t\t : GAGAL Clear !"
fi
if find _site/page* -type f -name 'index.html' |xargs sed -i 's/src="js\/modulku.js/src="..\/js\/modulku.js/g'
then echo -e "Page header 4 \t\t : OK, Clear....."
else echo -e "Page header 4 \t\t : GAGAL Clear !"
fi
ix = $( find . -name ".fuse_hidden00*" |wc -l ) ;
if [ " $ix " == "0" ]
then
echo -e "Remove .fuse_hidden00* \t : GAGAL, File Not Found !"
else
echo "Aada "
if rm .fuse_hidden00*
then
echo -e "Remove .fuse_hidden00* \t : OK, Clear....."
fi
fi
if [ " $1 " == "-" ]
then
pt = $( zenity --entry --title = "Copyt File" --text = "Input Destination Path : " ) ;
if sudo cp -rfu _site/ " $pt "
then
echo -e "Copy \t\t\t : OK, Copy to ' $pt ' Success......"
else
echo -e "Copy \t\t\t : GAGAL Copy to ' $pt ' !"
fi
fi
echo -e "BackUp Finished !..."
##--- Dengan menampilkan Notifikasi di layar desktop ---
notify-send "Selesai On_Web to Off_Web !" -i text-x-script
zenity --display :0 --info --width = 150 --height = 100 --title "BackUp Finished !" --text "Selesai Menyalin Web_on To Web_Off" # OK,
Post by : admin