2

I want to only save part of the output of script.py, and to a file in another folder.

script.py prints out a list of file names and their sizes, like

file_asfs.txt- 2KB
file_jsdfhkjh.doc- 17KB
....

If I want to save only the list of file names that are exactly 2KB in a text file /temp/filelist , how do I go about doing that?

1
  • 1
    In unix you can use sed, awk, grep, etc. to extract the parts you want from the output. Commented Nov 22, 2011 at 5:33

2 Answers 2

2
script.py | grep "\\b2KB$" > output.txt
Sign up to request clarification or add additional context in comments.

2 Comments

I want to only save the file names, not the whole string including names and sizes...
I got it, using a combination of grep and awk
1

you could create a program to filter it: filter.py:

import sys
for line in sys.stdin:
        line=line.strip()
        if line.endswith("- 2KB"):
                print line

then go

python script.py | python filter.py > /temp/filelist.txt

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.