LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   [Shell]Printing Content to File (https://www.linuxquestions.org/questions/programming-9/%5Bshell%5Dprinting-content-to-file-839864/)

whocares357 10-22-2010 05:23 PM

[Shell]Printing Content to File
 
I have this command (line):
Code:

tail -52 | find "/path/" -name "*.csv"
Instead of printing the contents of each file, the command prints the location of each file.
What am I doing wrong?

GrapefruiTgirl 10-22-2010 06:15 PM

Hi, welcome to LQ!

What exactly are you trying to accomplish?

How about something like:
Code:

echo > some_new_file

for file in $(find /search/path/ -type f -name "*\.csv"); do
    head -n 5 "$file" >> some_new_file
done

That prints the first 5 lines of all the files, into a new file. If this isn't what you're looking for, adjust the `head` command, or please explain some more.

:)

GrapefruiTgirl 10-22-2010 06:26 PM

Plus, if all your files are in one single directory, this will work for the same goal as above:
Code:

head -n 5 *.csv >> somefile

crts 10-22-2010 06:32 PM

How about
Code:

find "/path/" -name "*.csv" -exec tail -52 '{}' \;

whocares357 10-22-2010 11:10 PM

Thanks guys! I used the one crts gave me, but all of them are great.

grail 10-23-2010 12:43 AM

Please mark as SOLVED if you have a solution.


All times are GMT -5. The time now is 11:24 AM.