LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-09-2008, 10:23 AM   #1
shtek
LQ Newbie
 
Registered: Jan 2008
Posts: 2

Rep: Reputation: 0
piping and redirecting files


I want to trim some of the log files and hence i want to do something like

ls -la | grep log

this will give me a list of log files

for each log file I want to do
echo ""> filename

but i need to do it for each file so if i could combine these two command together thats great, bt dont know how..
 
Old 01-09-2008, 10:42 AM   #2
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,467

Rep: Reputation: Disabled
something like:

Code:
for log in `ls -la | grep log`
do
echo "" > $log
done
(untested)
 
Old 01-09-2008, 10:53 AM   #3
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
use shell expansion
Code:
for log in *log*
do
echo "" > $log
done
 
Old 01-09-2008, 11:28 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Just a side note: if the intent of the command
Code:
echo "" > logfile
is to clear the content of the file, you would use one of the following instead
Code:
: > logfile

echo -n > logfile
The former is the "null command", the latter is to avoid the trailing "newline" character. Indeed, if you simply overwrite the file with a zero-length string, the result will be a 1-byte file (and subsequent writes will leave a blank line at the beginning of the file).
 
Old 01-15-2008, 09:39 AM   #5
shtek
LQ Newbie
 
Registered: Jan 2008
Posts: 2

Original Poster
Rep: Reputation: 0
thanks

That worked >!!!!!!
 
  


Reply



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
Piping + redirection teddyZA Linux - General 6 04-10-2007 01:43 PM
piping snderr to less, can u do it? nvadekar Linux - Software 1 01-02-2007 12:37 AM
piping to 2 files simultaniously vineeth789 Programming 3 01-29-2006 05:43 PM
Help with piping mijohnst Linux - General 7 10-21-2005 04:14 PM
Piping output to text files corbis_demon Linux - General 3 10-12-2004 03:33 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:37 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration