Creating a loop to go through grep output


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Creating a loop to go through grep output
# 1  
Old 03-02-2012
Creating a loop to go through grep output

I'm doing this script in my Unix class and I've come to a roadblock. The purpose of this script is to search users directories for files that contain bad words i.e kill murder bomb etc., and then be able to ignore legitimate files with each use.
I got the searching and ignoring part down but now I need to put the info into the format my teacher wants, currently my output reads like this:
/home/badboy/bad: I want to kill him
/home/goodboy/good: I could kill for a pot pie

I however need it to look something like this
Username: badboy, Line with bad word found: I want to kill him, and Path and file name: /home/badboy/bad

The part I'm stuck on is creating a loop to go through each line of the grep output and cutting out want I want into variables to place in the proper format.
# 2  
Old 03-02-2012
For coursework and homework questions, please click here.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Creating for loop for tar -tvf doesnt work

hi all, i have created a for loop, it looks like this - #!/bin/bash cd /mnt/local/data/tars for tar in * do base=$(basename "$tar") "$base" -tvf >> /mnt/local/data/logs/"$base".csv done but i get this error - ./tar_loop.sh: line 8:... (2 Replies)
Discussion started by: robertkwild
2 Replies

2. Shell Programming and Scripting

Creating new file inside a for loop

Hi, I have list of files present in a folder. I want to search for a particular keyword sequentially and create a file which will be later used by some other program. Input files: $ ls a.dsx b.dsx c.dsx Dataline_.txt Dataline.txt loop.sh $ cat *.dsx help tyiis global for i in... (4 Replies)
Discussion started by: mac4rfree
4 Replies

3. OS X (Apple)

Having trouble creating an alias for grep

Hi, I'm using Mac 10.9.1. I would like to create an alias for grep so that it won't print out messages like "grep: /Users/davea/workspace/myproject/subdir/: Is a directory" all the time. So in my terminal, I opened ~/.profile and entered alias grep='grep -s' However, when I close and... (5 Replies)
Discussion started by: laredotornado
5 Replies

4. Shell Programming and Scripting

Creating a loop for multiplying columns

I have 2 files, that look like this: ID SNP1 SNP2 SNP3 SNP4 A1 1 2 0 2 A2 2 0 1 1 A3 0 2 NA 1 A4 1 1 0 2 and this: SNP score SNP1 0.5 SNP2 0.7 SNP3 0.8 SNP4 0.2 Basically, all of the SNP-values are 0,1, 2 or NA, and they each have a score, listed in the second file. The total... (5 Replies)
Discussion started by: kayakj
5 Replies

5. Shell Programming and Scripting

Creating variable by for loop

i have a file 'detail' which contains cat detail 111111 222222 333333 444444 but detail may be 4 line file.6 line file or 8 line file like cat detail 111111 222222 333333 444444 555555 666666 777777 888888 so i want a declare a loop which assign the value of first line in one... (11 Replies)
Discussion started by: rakeshtomar82
11 Replies

6. UNIX for Dummies Questions & Answers

creating shell loop homework help

Hello, i am new to unix and i had done very little assignment in unix. I need help on a homework assignment where i am require to create my own file call myshell. In the file it must have the commands that loop. Instead of displaying a regular command path like my computer name instead it is... (1 Reply)
Discussion started by: megaearth77
1 Replies

7. Shell Programming and Scripting

Creating a loop in csh

I have the following code and want to use a loop to output the results to the fparams file. if ($optparams == 1) then # Set the tdarwin parameters set txt01 = "Call to raytrac.csh" set txt02 = "" set txt03 = "./Scripts/raytrac.csh $*" set txt04 = "" set txt05 =... (0 Replies)
Discussion started by: kristinu
0 Replies

8. Shell Programming and Scripting

redirecting output and creating condition for while loop.

I have 2 questions. 1) Is there a means of directing output to a file (">") while making it still output to the console? I have a script that calls another lengthy script. 2) I can direct the output of the lengthy script and grep it for the words "good" or "bad" to know if I need the run... (2 Replies)
Discussion started by: mrwatkin
2 Replies

9. UNIX for Dummies Questions & Answers

Creating a one liner with wget, grep and mv

I have the following simplified script, that consists of a download (wget), a grab of only the lines with a comma (grep) and a rename of the file to indicate its date of origin (mv): wget http://www.example.com/datafile.csv grep ',' datafile.csv mv datafile.csv datafile.`date... (2 Replies)
Discussion started by: figaro
2 Replies

10. Shell Programming and Scripting

Creating loop for a script -Perl

Hi Guyz I designed a script that can compare 2 columns(values) of single file and gives the closest numbers to the first column by comparing the numbers in first column with second and it works in a single file. Now I'm trying to design a new script with 2 objectives for 2 files (not a single... (4 Replies)
Discussion started by: repinementer
4 Replies
Login or Register to Ask a Question