I am beginner
I would like to extract data ,which the file begins with "START OF TEC MAP" and ends with "END OF TEC MAP", from file. How can I get this specific interval? Which commands should I use?
Open the terminal and type:
uncompress -c codg0010.17i.Z | sed -n '/START OF TEC MAP/,/END OF TEC MAP/p'
To output the results to an output file instead type:
uncompress -c codg0010.17i.Z | sed -n '/START OF TEC MAP/,/END OF TEC MAP/p' >> output.txt
-i option of
sed is used for editing files in place. To extract the file from the archive and edit it in place instead of writing the output to output.txt:
uncompress codg0010.17i.Z # This archive has only 1 file in it named codg0010.17i. sed -ni '/START OF TEC MAP/,/END OF TEC MAP/p' codg0010.17i
This prints all the text between START OF TEC MAP and END OF TEC MAP, however this file contains not the data of just one TEC MAP but the data of 25 different TEC MAPs arranged sequentially and the above command prints the data of all 25 maps together.
sed part of the command has the following form:
sed -n '/WORD1/,/WORD2/p' /path/to/file
WORD1is the beginning string ( START OF TEC MAP )
WORD2is the end string ( END OF TEC MAP )
pis a sed command to print specific lines, in this case all lines including and between START OF TEC MAP and END OF TEC MAP
/path/to/fileis the either the path to the file or simply its name if your current directory is the same as the directory which contains the file.