grep and loop files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grep and loop files
# 1  
Old 06-16-2008
Data 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  
Old 06-16-2008
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  
Old 06-16-2008
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  
Old 06-16-2008
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  
Old 06-16-2008
MySQL 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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Ps ax with grep in loop

Hello, I have built the following script to check if processes supplied by the argument are running or not. #!/bin/bash PROCLIST=$1 PROCESS="0" ERROR_PROCS="" IFS='+' read -ra ADDR <<< "$PROCLIST" for PROC in "${ADDR}"; do if ; then PROCESS=1 ... (9 Replies)
Discussion started by: nms
9 Replies

2. UNIX for Beginners Questions & Answers

Loop grep, outputs in files

Hi, I try to create a simply code but I have problems... Ubuntum, Bash version: 4.3.46 Bash INPUT file (csv): TS133_29BC,xx2274305 TS133_29BC,rps4576240 av137_37BC,wfs2274305 av137_37BC,ftrs4576240 T1S138_30BC,rfss2255526 T1S138_30BC,rgas2274305 OUTPUT files (csv): File TS133_29BC... (6 Replies)
Discussion started by: echo manolis
6 Replies

3. Homework & Coursework Questions

GREP loop

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I need to search through the users home directories for keywords, display them. The code listed below will show... (7 Replies)
Discussion started by: jcllns1
7 Replies

4. Red Hat

using grep in a while loop

Hello everybody, I have been searching it, but it seems I am unable to find the correct information, that s why I am asking you guys, hoping somebody get an idea. Here is my problem : I want a script to loop until a string is identified in a log file. Here is the script : #!/bin/sh... (5 Replies)
Discussion started by: guyiom
5 Replies

5. Shell Programming and Scripting

Help on grep in a do while loop

So this is what I'm trying to do: I have a file called registry.txt which has a list of registry entries I want to search for. I have another file called inctrl.txt on which I want to perform the search on. Here's the example contents of registry.txt SOFTWARE\Microsoft\Security... (3 Replies)
Discussion started by: r4v3n
3 Replies

6. Shell Programming and Scripting

Using grep within a while loop

Hi all, I have the below script to get input but i cannot get grep to work. input1.txt AAAAAAAAG input2.txt >gi|184009.1| LEAFY-like |AAAAAAAAGSGGGDHLPY However, when i use grep -f input1.txt input2.txt i cannot get any output matches (note that the match is underlined). Is it... (8 Replies)
Discussion started by: turkishvan
8 Replies

7. Shell Programming and Scripting

Grep Different Files Using a Loop?

I have a script to GREP for a text expression within certain files, the files being named file.11012008 thru file.11302008. 30 files in all, one for each day of the month. Instead of entering the following 3 lines of code 30 different times, I'm trying to find a way to loop the process: ... (6 Replies)
Discussion started by: foleyml
6 Replies

8. Shell Programming and Scripting

Grep commands in loop

Hi All, Reference to my previous post I need to compare all the lines in the file1 with file2 for this condition if file1 {$3,$5} ==file2 {$3,$5} then grep file2{$1}latest date. need output in file3 10/04/2008 09/04/2008 09/04/2008 08/04/2008 can anyone suggest me Thanks... (0 Replies)
Discussion started by: karthikn7974
0 Replies

9. UNIX for Dummies Questions & Answers

grep -v while loop

alist contain: a b c d e blist contain: a b c the code: #!/usr/bin/ksh cat blist | while read line do grep -V "$line" alist > data done (8 Replies)
Discussion started by: bobo
8 Replies

10. Shell Programming and Scripting

grep in a loop

Hi , I am trying a script which takes user input userid . I am stuck how to check whether that is a valid user id or not in the audit log files. My code is : cd $CCP_AUDIT cat * > /export/home/$USR/l***/files echo "UserId:\c" read UserId #Date Function echo "DATE : \c" read xxx I... (7 Replies)
Discussion started by: gundu
7 Replies
Login or Register to Ask a Question