1. 程式人生 > >shell動態讀取資料夾下的檔案和檔名並替換到頁面上

shell動態讀取資料夾下的檔案和檔名並替換到頁面上

#! /bin/sh

NGINX_ROOT=/usr/share/nginx/html
INDEX_FILE=$NGINX_ROOT/index.html



#sed -i 's/url/urls/g' $INDEX_FILE

ls -1 /foo|awk -v cpath='/' 'BEGIN{print "["}{print "{url:\""cpath$0"\",name:\""$0"\"},"}END{print "]"}' > ~/json.txt

REAL_PATH=`cat ~/json.txt`

echo "$REAL_PATH"
prefix_path="urls:"
path="${prefix_path}${REAL_PATH}"","
echo $bbb



exp="'s|^.*name.*$|$path|g'"
echo $exp
sed_cmd="sed -i $exp  $INDEX_FILE"
echo $sed_cmd

eval $sed_cmd

在朋友的幫助下,弄了好幾天終於弄出來了,感覺已經奔潰。

相關推薦

shell動態讀取資料檔案檔名替換面上

#! /bin/sh NGINX_ROOT=/usr/share/nginx/html INDEX_FILE=$NGINX_ROOT/index.html #sed -i 's/url/urls/g' $INDEX_FILE ls -1 /foo|awk -v cpath=

Mapreduce如何獲取讀取資料檔案的名字

 需要注意的導包的時候導這兩個包                     import

python 讀取資料檔案,將檔名作為製作標籤,訓練樣本

# -*- coding: utf-8 -*- import os import re path = "F:\\data\\test_Data" # 更改檔名 def Rename_file(path

C++ 讀取資料的所有檔名

那麼到底如何查詢檔案呢?我們需要一個結構體和幾個大家可能不太熟悉的函式。這些函式和結構體在<io.h>的標頭檔案中,結構體為struct _finddata_t ,函式為_findfirst、_findnext和_fineclose。具體如何使用,我會慢慢講來~         首先講這個結構體吧

matlab查詢指定資料檔案(附漢字標點符號讀取方法)

fidrrt = fopen('F:\lyn.txt'); while 1 tline = fgetl(fidrrt); if ~ischar(tline), break, e

ndk讀取資料檔案列表

char *dir_path = "/mnt"; DIR *dir = opendir(dir_path); if (dir == NULL) { LOGD("open dir error!"); return -1; }

讀取資料非隱藏檔案及SBU資料rgb提取

函式 listdir_nohidden讀取檔案時去掉隱藏檔案 import os import shutil def listdir_nohidden(path): p = [] for f in os.listdir(path):

PHP遞迴非遞迴遍歷資料檔案

function readDirFiles($dir){ $files= []; $queue=[realpath($dir)]; $currentPath = current($queue); while($currentPath) {

Python統計資料資料檔案個數

很簡單的功能,但是發現網上的例子都不對啊: import os file_count=0 for dirpath, dirnames, filenames in os.walk('待分析目錄'):

shell 指令碼統計資料所有檔案的字元數

最近寫了一些文章存放在一個資料夾下,今天想看看自己到底寫了多少內容。於是想寫一個指令碼來進行統計。最終程式碼如下: #!/bin/bash files=$(ls) all=0 for i in

springboot打成jar包後無法讀取resource資料檔案模板---------------gxy

springboot打成jar包後無法讀取resource資料夾下檔案模板 BufferedInputStream bis = null; OutputStream os = null; Cla

python 讀取資料多個檔案

import os os.chdir("G:\head in python\hfpy_ch5_data") L=[] for files in os.walk("G:\head in python\hfpy_ch5_data"): for file i

python讀取資料所有csv檔案

### 讀取資料夾下的所有csv檔案 import os # 輸出資料夾下的所有檔案 os.listdir('../data/simulation_data_generation/pdata2_100

Linux C 讀取資料所有檔案(包括子資料)的檔名

Linux C  下面讀取資料夾要用到結構體struct dirent,在頭#include <dirent.h>中,如下: #include <dirent.h> struct dirent { long d_ino; /* inode number 索引節點號

基於C/C++的讀取資料所有檔案(圖片、文件等)的程式碼

<pre name="code" class="cpp">#include <iostream> #include <string> #include <vector> #include <io.h> #inclu

【Python】Python讀取資料的所有檔案

 os.listdir(path)是得到在path路徑下所以檔案的名稱列表。     open(path)是開啟某個檔案。    iter是python的迭代器。        所以讀取某資料夾下的所

windows讀取資料所有的檔案——C++

intptr_t hFile = 0; struct _finddata_t fileInfo; std::string pathName, exdName;

fso獲取資料檔案個數顯示檔名(無後綴)

 感謝sayhito333提供給我這段程式碼,為表示感謝,不修改其宣傳性的函式名了,呵呵! <%path = "database/"sub sayhito333(path)dim fsodim objFolderdim objFilesdim objFiledi

WPF 批量讀取資料TXT檔案寫入EXCEL

 把翻到的很多以前寫的程式做個記錄,記錄學習過程,同時也方便以後查閱 https://github.com/Yiomo/ReadInfo 該APP會讀取選定資料夾下的TXT檔案並且直接將資訊按行寫入當前目錄下的excel表格 PS.需要excel2010以上的元件&

LinuxWindows系統C++讀取資料檔名

參考部落格     我的開發環境為Ubuntu+Qt,讀取資料夾下檔名時會找不到io.h,通過查詢資料瞭解到Windows和Linux下的標頭檔案是不一樣的,下面首先介紹Linux系統下檔名的獲取 一、Linux系統下檔名獲取 (1)C語言版本 //LINUX/UNIX