iOSecure
iOSecure

Reputation: 232

Split file based on text inside file

I'm trying to have this file split into other files. So it would take all of the lines with "data.pdf" in it from the input file and make a text file called data.pdf.txt

The data I am trying to have split is in column 5 below.

Input:

/mnt/Hector/Data/benign/binary/benign-pete/ d16feafae3adf1ee0f77e6a84a476b18    0   S043GUIv02  code.bin.pe32.gui   PE32 executable for MS Windows (GUI) Intel 80386 32-bit
/mnt/Hector/Data/benign/binary/benign-pete/ e9f6b4a413ed42987e1bfff13954faaa    0   S043GUIv02  code.bin.pe32.gui   PE32 executable for MS Windows (GUI) Intel 80386 32-bit
/mnt/Hector/Data/benign/binary/benign-pete/ 01d0cd964020a1f498c601f9801742c1    19  S040PDFv02  data.pdf    PDF document
/mnt/Hector/Data/benign/binary/benign-pete/ 0299a1771587043b232f760cbedbb5b7    0   S040PDFv02  data.pdf    PDF document

thanks I have been stuck on this and cannot do it correctly

Upvotes: 0

Views: 76

Answers (2)

fedorqui
fedorqui

Reputation: 290125

This checks if the 5th column is data.pdf. If so, it prints the result in data.pdf.txt.

$ awk '$5 == "data.pdf"' your_file
/mnt/Hector/Data/benign/binary/benign-pete/ 01d0cd964020a1f498c601f9801742c1    19  S040PDFv02  data.pdf    PDF document
/mnt/Hector/Data/benign/binary/benign-pete/ 0299a1771587043b232f760cbedbb5b7    0   S040PDFv02  data.pdf    PDF document

And like this, it creates "data.pdf.txt" with this content:

$ awk '$5 == "data.pdf"' your_file > data.pdf.txt

Upvotes: 1

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799150

awk '{ print >> $5.txt }' < input.txt

Upvotes: 1

Related Questions