How can I extract data from UNIX file?
Solution 1:
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
The -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.
Explanation
The sed
part of the command has the following form:
sed -n '/WORD1/,/WORD2/p' /path/to/file
-
WORD1
is the beginning string ( START OF TEC MAP ) -
WORD2
is the end string ( END OF TEC MAP ) -
p
is 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/file
is 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.