1

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?

File: codg0010.17i.Z

5

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.
  • Is it possible to edit the file instead of output.txt? Just these values not other things in the same file. – S.YAZICI May 20 '18 at 17:18
  • I added the command to edit the file instead of outputting it to output.txt to my answer. – karel May 20 '18 at 17:32
  • It didn't work or I did wrong. – S.YAZICI May 20 '18 at 19:39
  • 1
    @S.YAZICI please edit your question to clarify exactly what your requirement is - "edit the file" is quite a bit different from "extract the data" – steeldriver May 20 '18 at 21:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.