Chinaunix
标题:
提取某列数的问题
[打印本页]
作者:
McFinalo
时间:
2011-08-05 18:03
标题:
提取某列数的问题
问题是这样的:有很多列数,数和数之间用“;”隔开,如何提取任意列的数据呢?
举个例子:数据如下
7;2;4;0;0;0-22;24-0;1;40;1;2;0;201168;4;158;33;175;-4678;2;73.0;24448774.1;0.4;444.8;-11141314.4;21888603.4;-9807351.3;-124.8;-1318.1;-2763.3;0;0
7;2;4;0;0;0-22;25-0;-1;39;0;2;0;201168;4;183;33;175;-4677;17;63.0;24449219.4;0.4;445.2;-11141376.8;21887944.3;-9808732.9;-124.8;-1318.3;-2763.2;0;0
7;2;4;0;0;0-22;25-0;-1;39;0;2;0;201168;4;208;33;175;-4677;18;53.0;24449664.4;-0.2;445.0;-11141439.3;21887285.1;-9810114.5;-124.8;-1318.5;-2763.1;0;0
7;2;4;0;0;0-22;25-0;1;39;0;2;0;201168;4;233;33;175;-4676;6;43.0;24450108.9;-0.4;444.6;-11141501.7;21886625.8;-9811496.0;-124.8;-1318.7;-2763.0;0;0
7;2;4;0;0;0-22;25-0;0;40;1;2;0;201168;4;258;33;175;-4675;21;34.0;24450559.5;6.0;450.6;-11141564.1;21885966.4;-9812877.5;-124.9;-1318.8;-2762.9;0;0
7;2;4;0;0;0-22;25-0;0;40;0;2;0;201168;4;283;33;175;-4674;7;30.0;24451012.6;2.6;453.1;-11141626.5;21885307.0;-9814258.9;-124.9;-1319.0;-2762.8;0;0
7;2;4;0;0;0-22;25-0;0;40;0;2;0;201174;5;8;33;175;-4672;31;30.0;24451471.2;5.5;458.6;-11141689.0;21884647.4;-9815640.3;-124.9;-1319.2;-2762.7;0;0
7;2;4;0;0;0-22;25-0;0;42;2;2;0;201174;5;33;33;175;-4670;42;30.0;24451931.0;1.2;459.8;-11141751.4;21883987.8;-9817021.6;-124.9;-1319.3;-2762.6;0;0
7;2;4;0;0;0-22;25-0;0;42;0;2;0;201174;5;58;33;175;-4668;45;30.0;24452390.4;-0.3;459.4;-11141813.8;21883328.1;-9818402.9;-124.9;-1319.5;-2762.5;0;0
7;2;4;0;0;0-22;25-0;0;42;0;2;0;201174;5;83;33;175;-4666;53;30.0;24452849.9;-0.0;459.4;-11141876.3;21882668.3;-9819784.1;-124.9;-1319.7;-2762.4;0;0
7;2;4;0;0;0-22;25-0;0;42;0;2;0;201174;5;108;33;175;-4663;52;30.0;24453307.8;-1.4;458.0;-11141938.7;21882008.4;-9821165.3;-124.9;-1319.8;-2762.3;0;0
7;2;4;0;0;0-22;25-0;-1;41;0;2;0;201174;5;133;33;175;-4661;50;30.0;24453763.0;-2.9;455.1;-11142001.2;21881348.5;-9822546.4;-124.9;-1320.0;-2762.2;0;0
7;2;4;0;0;0-22;25-0;0;41;0;2;0;201174;5;158;33;175;-4658;52;30.0;24454215.6;-2.5;452.6;-11142063.6;21880688.4;-9823927.5;-124.9;-1320.2;-2762.1;0;0
7;2;4;0;0;0-22;25-0;-1;40;0;2;0;201174;5;183;33;175;-4656;52;30.0;24454667.4;-0.9;451.8;-11142126.1;21880028.3;-9825308.5;-124.9;-1320.3;-2762.0;0;0
7;2;4;0;0;0-22;25-0;1;43;2;2;0;201174;5;208;33;175;-4653;46;30.0;24455117.3;-1.9;449.9;-11142188.5;21879368.1;-9826689.4;-124.9;-1320.5;-2761.9;0;0
7;2;4;0;0;0-22;25-0;0;43;0;2;0;201174;5;233;33;175;-4651;37;30.0;24455565.8;-1.3;448.6;-11142251.0;21878707.8;-9828070.3;-124.9;-1320.7;-2761.7;0;0
7;2;4;0;0;0-22;24-0;0;43;0;2;0;201174;5;258;33;175;-4650;25;29.0;24456012.8;-1.6;447.0;-11142313.4;21878047.4;-9829451.2;-124.9;-1320.8;-2761.6;0;0
如何提取任意列的呢:我初步想法是用sed,但是弄了半天,没搞定,各位达人支个招~~~
先把我的代码贴出来:
show_help(){
cat <<EOF
Usage: configure parm0 parm1 parm2
parm0: FileName
parm1: SvID
parm2: name of the value want to be plot
name must be one of below
@channel
@Status
@LoopMode
@DllPd
@FllPd
@state
@RtCN0
@CN0
@CN1
@SvPrValid
@DltRtCN0
@TOW
@sf_id
@bit_cnt
@el
@az
@Doppler
@DeltaDoppler
@PllVal
@sv_pr
@delta_dpr
@delta_pr
@posx
@posy
@posz
@velx
@vely
@velz
@pe_i
@pe
EOF
exit 0
}
if [ "$#" -ne 3 ]
then
echo "parmeter num error,3 pramters are needed"
show_help
fi
if [[ "$2" < 0 ]]
then
echo "SvID error0"
exit 0
fi
if [[ "$2" > 99 ]]
then
echo "SvID:" "$2" "error"
exit 0
fi
fileName="$3"
mode0=.*
mode1=.*
case "$3" in
channel)
mode0='s/\//;/g'
mode1='s/;.*//g'
;;
Status)
mode0='s/[0-9];//p'
mode1='s/;.*//g'
;;
LoopMode)
mode0='s/[0-9];[0-9];//g'
mode1='s/;.*//g'
;;
DllPd)
mode0='s/[0-9];[0-9];[0-9];//g'
mode1='s/;.*//g'
;;
FllPd)
mode0='s/[0-9];[0-9];[0-9];[0-9];//g'
mode1='s/;.*//g'
;;
state)
mode0='s/[0-9];[0-9];[0-9];[0-9];[0-9];//g'
mode1='s/-.*//g'
;;
RtCN0)
mode0='s/^[0-9]*;.*;.*;.*;.*;.*;.*;//g'
mode1='s/;.*//g'
;;
CN0)
mode0='s/^[0-9]*;.*;.*;.*;.*;.*;.*;.*;//g'
mode1='s/;.*//g'
;;
CN1)
mode0='s/^[0-9]*;.*;.*;.*;.*;.*;.*;.*;.*;//g'
mode1='s/;.*//g'
;;
SvPrValid)
mode0='s/^[0-9]*;.*;.*;.*;.*;.*;.*;.*;.*;.*;//g'
mode1='s/;.*//g'
;;
DltRtCN0)
mode0='s/^[0-9]*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;//g'
mode1='s/;.*//g'
;;
TOW)
mode0='s/^[0-9]*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;//g'
mode1='s/;.*//g'
;;
sf_id)
mode0='s/^[0-9]*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;//g'
mode1='s/;.*//g'
;;
bit_cnt)
mode0='s/^[0-9]*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;//g'
mode1='s/;.*//g'
;;
el)
mode0='s/^[0-9]*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;//g'
mode1='s/;.*//g'
;;
az)
mode0='s/^[0-9]*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;//g'
mode1='s/;.*//g'
;;
Doppler)
mode0='s/^[0-9]*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;//g'
mode1='s/;.*//g'
;;
DeltaDoppler)
mode0='s/^[0-9]*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;//g'
mode1='s/;.*//g'
;;
PllVal)
mode0='s/^[0-9]*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;//g'
mode1='s/;.*//g'
;;
sv_pr)
mode0='s/^[0-9]*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;//g'
mode1='s/;.*//g'
;;
delta_dpr)
mode0='s/^[0-9]*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;//g'
mode1='s/;.*//g'
;;
delta_pr)
mode0='s/^[0-9]*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;//g'
mode1='s/;.*//g'
;;
posx)
mode0='s/^[0-9]*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;//g'
mode1='s/;.*//g'
;;
posy)
mode0='s/^[0-9]*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;//g'
mode1='s/;.*//g'
;;
posz)
mode0='s/^[0-9]*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;//g'
mode1='s/;.*//g'
;;
velx)
mode0='s/^[0-9]*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;//g'
mode1='s/;.*//g'
;;
vely)
mode0='s/^[0-9]*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;//g'
mode1='s/;.*//g'
;;
velz)
mode0='s/^[0-9]*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;//g'
mode1='s/;.*//g'
;;
pe_i)
mode0='s/^[0-9]*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;//g'
mode1='s/;.*//g'
;;
pe)
mode0='s/^[0-9]*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;.*;//g'
mode1='s/;.*//g'
;;
esac
echo $mode0
echo $mode1
file="$1"
svid=0-"$2"
dos2unix $file
cat $file | sed $mode0 | sed $mode1 >> log.txt
作者:
lkk2003rty
时间:
2011-08-05 18:12
用awk 设分隔符为 ;
作者:
McFinalo
时间:
2011-08-05 18:13
呃,谢谢~我试试看
作者:
mpstat
时间:
2011-08-05 18:14
cut -d';' -fN file
N就是你要提的列
作者:
Shell_HAT
时间:
2011-08-05 20:54
awk -F ';' '{print $3}' urfile
复制代码
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2