抱歉造成混乱,我需要一个脚本,我的要求是如果我有包含标题、记录和尾部的文本文件,例如:- Test1.txt(输入文件)
例如
我有一个文本文件
输入文件
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 shell 脚本,它将根据它们的位置从输入文件中提取特定的列数据,因为我没有分隔符,甚至没有空格。在这里我必须提取一些列(我可以根据它们的位置随机选择) 并将它们保存到文本文件
假设例如:如果我需要一个应该从位置 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
我的第二个要求
现在输出与第一个输出文件相同,但在这里我可以选择一些不同的列,但它
应该包含带有标题、记录、尾部的数据,
例如:
打印作为标题的第一行,然后我有记录和尾部
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