The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Grep commands in loop karthikn7974 Shell Programming and Scripting 0 04-28-2008 09:16 AM
grep and awk showing filename in loop sjohns6 Shell Programming and Scripting 5 05-24-2007 08:59 AM
grep -v while loop bobo UNIX for Dummies Questions & Answers 8 01-26-2007 10:53 PM
grep in a loop gundu Shell Programming and Scripting 7 03-28-2005 04:59 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rating: Thread Rating: 1 votes, 2.00 average. Display Modes
  #1 (permalink)  
Old 06-15-2008
kashik kashik is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 2
Unhappy grep and loop files

Hi ,
1. I want to grep two or three lines from a set of files and put the grepped lines into again a set of files.like
file1-greppedfile1
file2-greppedfile2

then again do some format to the grepped files with sed or awk then create another set of files.
How can I do this in loop?

2.I want to grep a date within a file.The date is at almost end of the file
but there are also some dates above the last date format which i have to grep.

Help will be appreciated...

Thanks
  #2 (permalink)  
Old 06-16-2008
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,419
Do not post questions without trying to solve the problem yourself based on your understanding. Post what have you tried so far and where exactly are you stuck?
  #3 (permalink)  
Old 06-16-2008
spirtle spirtle is offline
Registered User
  
 

Join Date: Jun 2008
Location: Scotland
Posts: 150
Your second problem looks like you want to get from a file the last line containing a date. If so, then try something like
Code:
grep date file | tail -n 1
I'm afraid I don't understand your first problem; give us an example?
  #4 (permalink)  
Old 06-16-2008
kashik kashik is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 2
I did it for one file

Hi,
I am beginner in shell scripting.I have done the grep for one file like

grep -i 'abcd' from file1>file2
grep '1234' from file1>>file2

then by awk I have divided '1234/234' and appended file2>file3.

This I have to do it for 5 files.
for each file there must be seperate result file.I can do it manually but this is to be run like a job.
I hope you got my my problem..
  #5 (permalink)  
Old 06-16-2008
nua7 nua7 is offline
Registered User
  
 

Join Date: Mar 2008
Location: /bin/sh
Posts: 353
Thumbs up Not the most efficient, but give it a try..

Alrighty, this might not be the most efficient way of doing this, but you can give this a try..

suppose you have file1, file2,file3,file4 and so on to grep,



Code:
arg1=abcd
arg2=1234
for i in file*
do
grep -i $arg1 $i >$arg1_$i
grep -j $arg2 $i >$arg2_$i
done

find . -empty | xargs rm
This should do the trick.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:04 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0