解決:我的一個好朋友寫了下面的程序對我來說:拆分一個大的文本文件轉換成列
filename="my_input_file"
context="channel" # this is the key which separates the blocks in the input file
desired_column_separator="," # this will separate the columns in the output file
output_prefix="modified_" # prefix for the output file
if [ -d ./tmp ]
then
echo " "
echo "***WARNING***"
echo "I want to use and delete a ./tmp/ directory, but one already exists... please remove/rename it, or alter my code***"
echo " "
exit
fi
mkdir ./tmp
cd ./tmp
csplit -z -n 4 ../$filename /$context/ {*} 1> /dev/null
filenum=`ls -1 ./ | wc -l`
limit=`echo "$filenum - 1" | bc -l`
lines=`wc -l < xx0000`
touch tmp.dat
for j in `seq 1 $lines`
do
oldstring=''
for i in `seq 0 $limit`
do
inputNo=`printf "%04d" $i`
string=`head -n $j 'xx'$inputNo | tail -n 1`
oldstring=$oldstring$string$desired_column_separator
done
finalstring=`echo $oldstring | tr -d '\r' | tr -d '\n'`
echo "working on line "$j" out of "$lines
echo -n $finalstring >> tmp.dat
echo -e "\r" >> tmp.dat
done
mv tmp.dat ../$output_prefix$filename
cd ..
rm -r -f ./tmp/
echo "...done!"
原文:我知道分裂的文本文件已經完成,在這個論壇的死亡,但我不能找不到特定於我的問題的方法。 我想將一個大文件(> 200mb)分割成文本行的列,但'split'函數會將每一列放入它自己的文件中。說實話,3,000多個單獨的文件文本是加載到其他程序中的一種痛苦。最重要的是,我還想提取文本文件的一部分作爲我的數據的標題(第4行的最後一部分)。 最初文件由一列的,就像這樣:
channel names:
03/02/2012 12:03:03 - TDS3k(CH1)
start times:
03/02/2012 12:08:02.311422
dt:
0.000000
data:
-8.000000E-4
-8.000000E-4
-1.600000E-3
... (9,994 lines omitted)
-2.400000E-3
-1.600000E-3
-2.400000E-3
channel names:
03/02/2012 12:03:03 - TDS3k(CH1)
start times:
03/02/2012 12:33:11.169533
dt:
0.000000
data:
-8.000000E-4
-1.600000E-3
-1.600000E-3
... (another 9,997 lines omitted)
我想它看起來像這樣:
channel names: channel names:
03/02/2012 12:03:03 - TDS3k(CH1) 03/02/2012 12:03:03 - TDS3k(CH1)
start times: start times:
03/02/2012 12:08:02.311422 03/02/2012 12:33:11.169533
dt: dt:
0.000000 0.000000
data: data:
-8.000000E-4 -8.000000E-4 ...
-8.000000E-4 -1.600000E-3 ...
-1.600000E-3 -1.600000E-3 ...
... ...
我懷疑越來越分裂在正確的地方是比較容易做的比標題,但我不夠好做任何一個。
在此先感謝
編輯:我還沒有使用任何特定的語言。我只需要一種格式的數據,我可以在R中進行分析。我會根據你們的建議來解決這個問題。
你想使用什麼編程語言? – ChrisWue 2012-02-06 00:11:24
您知道,您可能只想提供一點關於您正在使用的工具(語言/電子表格/數據庫/其他)的提示。 – 2012-02-06 00:11:48
我沒有使用任何特定的語言。 'sed'和'awk'都是朋友建議的,但我無法讓他們工作。我會在某些時候將它加載到R中。 – user1191276 2012-02-06 03:32:33