LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-22-2010, 05:23 PM   #1
whocares357
LQ Newbie
 
Registered: Oct 2010
Posts: 7

Rep: Reputation: Disabled
[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?
 
Old 10-22-2010, 06:15 PM   #2
GrapefruiTgirl
Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
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.

 
Old 10-22-2010, 06:26 PM   #3
GrapefruiTgirl
Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
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
 
Old 10-22-2010, 06:32 PM   #4
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,604

Rep: Reputation: 446Reputation: 446Reputation: 446Reputation: 446Reputation: 446
How about
Code:
find "/path/" -name "*.csv" -exec tail -52 '{}' \;
 
Old 10-22-2010, 11:10 PM   #5
whocares357
LQ Newbie
 
Registered: Oct 2010
Posts: 7

Original Poster
Rep: Reputation: Disabled
Thanks guys! I used the one crts gave me, but all of them are great.
 
Old 10-23-2010, 12:43 AM   #6
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,492

Rep: Reputation: 1891Reputation: 1891Reputation: 1891Reputation: 1891Reputation: 1891Reputation: 1891Reputation: 1891Reputation: 1891Reputation: 1891Reputation: 1891Reputation: 1891
Please mark as SOLVED if you have a solution.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
printing terminal content to a file mahmoodn Linux - General 12 05-16-2010 06:17 AM
shell script for changing a txt file content Flobsi Linux - Newbie 3 10-06-2006 03:10 AM
shell script for changig txt-file content Flobsi Programming 1 10-05-2006 05:46 PM
modify content in a file using shell script fjkum Linux - Newbie 2 08-03-2006 04:46 AM
[c shell] printing out each line in a file saiz66 Programming 4 10-12-2004 08:15 AM


All times are GMT -5. The time now is 03:32 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration