I want to thank you all again for the replies. When I first read your comments about the standout output issues, I really didn't understand what you were talking about. Today I had to use the grep results and manipulate it with sed. I noticed after the sed, the file names were not lined up in the right place. I re-read your replies many times and did a lot of debugging. I finally understand!!!
Don't know if it's the best way to fix the problem but it does the job:
for targz in *.tar.gz
echo "$targz" >&1
tar -tf $targz | grep folder1/folder2>&1
done | sed ...
I wouldn't know to do any of these if you did not make the suggestions.
Thank you very much!!!
Glad you benefited from these fora, and hope you will in the future.
Two comments, though:
- the >&1 is pointless, as it means "duplicate fd1 (file descriptor) from fd1", and echo writes to fd1 anyhow.
- as sed has "grepping" capabilities by default, why don't you do everything needed in one sed command? If you need help on this, pls. post sample data and specific requirements.
When I was started testing, the grep ... was put after the done. As a result, I only saw the grep results without the filenames so it appeared the filenames were "missing". I added the >&1 to make sure the filenames go to standad output because I didn't know why the names were "missing" at that time. I finally moved the |grep ... inside the loop and the names showed up in the output.
After reading your comments, I removed the >&1 and I still got the same output. Cool. Thank you.
Whoa, sed has grep capabilities??? Let me read about it first and if I still need help, I will post a new thread. Thank you!
Note that xargs reads a file one line at a time or it gets the equivalent data via a pipe. Its input file could be something you created/edited or from an ls or find command. The first argument of xargs is the command you want to run, other arguments are parameters (if any) of that command. Other arguments of your command are the list read into xargs.
For example, if myfile.txt contains:
you could look for the word sample in all three files, ignoring case with the line
xargs <myfile.txt grep -i sample
--- and what would be excuted is ---
grep -i sample file1 file2 file3