-4

混乱を招いて申し訳ありません。スクリプトが必要です。私の要件は、ヘッダー、レコード、およびテールを含むテキスト ファイルがある場合
です

入力ファイル

test1.txt   
---------   
2013101000490398938---HEADER
rohitroshankavuriM26single2010198702092013000(4053 characters each line contains)
rohitroshankavuriM26single2010198702092013000(4053 characters each line contains)
rohitroshankavuriM26single2010198702092013000(4053 characters each line contains)
rohitroshankavuriM26single2010198702092013000(4053 characters each line contains)
rohitroshankavuriM26single2010198702092013000(4053 characters each line contains)
201310100004005--TAIL

区切り文字やスペースさえないため、位置に基づいて入力ファイルから特定の列データを抽出する UNIX シェル スクリプトを作成する必要があります。 )、テキスト ファイルに保存します。

たとえば、次のように、位置 1-5,6-8,9,10-12 からデータを抽出する必要があり、ヘッダーとテールを含めないテキスト ファイルが必要な場合。

normally i have used this script to

#Create as same as the input file    
cat Test1.txt>tmp.txt    
#here i will delete the header and tail from the tmp.txt file    
sed '1d,$d' tmp.txt    
#now i will extract the data based upon the    
cut 1-5,6-8,9,10-12 Test1.txt>Test2.txt  

O/Pはこんな
感じ Test2.txt
---------
rohitroshank
rohitroshank
rohitroshank
rohitroshank

これで、最初の出力ファイルの準備ができました Test2.txt

私の2番目の要件

最初の出力ファイルと同じ出力ですが、ここではいくつかの異なる列を選択できますが
、ヘッダー、レコード、テールなどのデータが含まれている必要があります

ヘッダーである最初の行を印刷するには、その後、レコードがあり、テールの後にあります

Test3.txt(output file)      
--------------------------    
 #to print the head    
 head -1 tmp.txt>Test3.txt     
 #now i will pick specific columns based upon my positions & append it to test3.txt
 cut 13-15,16-19,20 tmp.txt>>Test3.txt    
 #print and append it to Test3.txt file     
 tail -1 tmp.txt>>Test.txt 

出力 Test3.txt

2013101000490398938
avuriM26
avuriM26
avuriM26
avuriM26
avuriM26
avuriM26
avuriM26
201310100004005

今まで私の要件は完了しましたが、この出力を取得する他の簡単な方法はありますか? はいの場合は、スクリプトを共有してください。

And but also now i am stuck with a problem i.e     
extracting specific columns data using CUT command.see any text file      
each line will contain 1024 characters but i have 4093 characters so how would i 
approach this requirement rather than doing it using CUT.

Is there any other way please suggest me. If are having any queries regarding my
requirement comment it here
4

2 に答える 2

0
#!/bin/bash
tail -n +2 test1.txt | head -n -1 > test2.txt
cp test1.txt test2.txt
exit 0
于 2013-10-15T10:38:36.210 に答える