Help with grep and read function in a BASH Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with grep and read function in a BASH Script
# 1  
Old 08-04-2011
Help with grep and read function in a BASH Script

I'm putting together a script that will search my mail archives for emails that meet certain criteria and output the files to a text file.

I can manually cat that text file and pipe it into sendmail and it will work (i.e. cat /pathtofile/foo.txt | sendmail -t me@company.com)


My script sends a list of the files to a text file and is suppost to read the filename on each line and email it to me but all im getting is a text blank emails so it doesn't appear to be reading lines correctly.
(i.e. cat /tmp/foo.txt | while read i; echo "$i" | sendmail -t me@company.com)

I don't know if it makes a diffrence but the text file lines are automatically formatted like this:

./1312288621.V804I59c1aaa3M731667.sam.company.local:To: "My Name" <me@company.com>,
./1312289223.V804I59c1aad4M503269.sam.company.local:To: "My Name" <me@company.com>


The only parts that of the file that are needed are:

1312288621.V804I59c1aaa3M731667.sam.company.local
1312289223.V804I59c1aad4M503269.sam.company.local

Last edited by binary-ninja; 08-04-2011 at 06:19 PM..
# 2  
Old 08-04-2011
Use grep -l ?
# 3  
Old 08-04-2011
Maybe I explained it wrong,

I'm trying to strip the ./ from the begining of every line
and then strip everything after sam.company.local
# 4  
Old 08-04-2011
Code:
awk -F"[/:]" '{print $2}' foo.txt | while read line; do echo "$line"; done;

# 5  
Old 08-04-2011
Do you know if a way to cat or pipe the contents of the awk line that you gave me?

I try to pipe it and it gives me an error and if I redirect it it gives me a empty file
# 6  
Old 08-04-2011
Quote:
Originally Posted by binary-ninja
Do you know if a way to cat or pipe the contents of the awk line that you gave me?

I try to pipe it and it gives me an error and if I redirect it it gives me a empty file
Code:
awk -F"[/:]" '{print $2}' foo.txt >> outfile

Code:
[root@localhost ugr]# cat outfile
1312288621.V804I59c1aaa3M731667.sam.company.local
1312289223.V804I59c1aad4M503269.sam.company.local

this works fine with me, im testing it in Red Hat 5.5
This User Gave Thanks to EAGL€ For This Post:
# 7  
Old 08-04-2011
odd, I wonder if ubuntu interpretes awk diffrently

awk -F"[/:]" '{print $2}' /tmp/foo.txt | while read line; do echo "$line"; done;

prints to screen

but the following just gives me a empty file

awk -F"[/:]" '{print $2}' /tmp/foo.txt | while read line; do echo "$line"; done; >> /tmp/foo2.txt
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to pass and read an array in ksh shell script function.?

I'm able to read & print an array in varaible called "filelist" I need to pass this array variable to a function called verify() and then read and loop through the passed array inside the function. Unfortunately it does not print the entire array from inside the funstion's loop. #/bin/ksh... (5 Replies)
Discussion started by: mohtashims
5 Replies

2. Shell Programming and Scripting

Grep -q -F , what is the function of this script

Hello, I checked grep help field, I got the answer but seems a bit technical for me. Could you please let me know what is this script doing? grep -q -F 'addprestart.sh' /usr/bin/enigma2_pre_start.sh || \ echo '/bin/sh /etc/enigma2/addprestart.sh > \ /dev/null 2>&1 & sleep .5 &' >>... (6 Replies)
Discussion started by: baris35
6 Replies

3. Shell Programming and Scripting

Read function is going in infinite in another script having while loop

Hello Experts, I have created one user confirmation process that will ask for user input. I have created one func for it. The issue is if i call it as normal then it works fine but if i am calling it in another script(in while loop) . It is going in infinite loop and not asking for user input. ... (8 Replies)
Discussion started by: looney
8 Replies

4. Shell Programming and Scripting

[Bash] Read History function & Read Arrowkeys

Hi. How can I create a history function? (By "read" command or so) & How can I configure a read command so that the arrow keys are not displayed so funny? (^[[A) Thanks in advance. (4 Replies)
Discussion started by: sinnlosername
4 Replies

5. Shell Programming and Scripting

Calling function from another bash script

I would like to call functions from another bash script. How can I do it? Some code More code (11 Replies)
Discussion started by: kristinu
11 Replies

6. Shell Programming and Scripting

bash read within function with arguments

I have trouble getting this logic to work #!/bin/bash function assign_var(){ while do read -p "$2 :" $3 done } assign_var '$IPADDRESS' ipaddress IPADDRESS Basicly, i want to make sure that entry is made (i can add more sophisticated checks later), but the idea is to recycle... (11 Replies)
Discussion started by: serverchief
11 Replies

7. Shell Programming and Scripting

bash script function parameters

I have a question about bash script. Can I create a function there that accept parameters like functions in program language? (2 Replies)
Discussion started by: programAngel
2 Replies

8. Shell Programming and Scripting

error when call function in bash script

Dear all, Could you please advice as I when call function i found the following error " refills: command not found" note that refills is function name. following also the function and how i call it function refills { echo "formatting refills and telepin" >> $log awk -F,... (20 Replies)
Discussion started by: ahmed.gad
20 Replies

9. Shell Programming and Scripting

Run function from script over ssh (BASH)

Hi, Is there any cleaver way to run function from the bash scrip over ssh? For example: #!/bin/bash #Function 1 FN1 () { ls -l } #Main run ssh user@host FN1 exit 0 Yeah, I know it will not work, but I'm asking how to make it to work :) I'm suspecting that it would be... (1 Reply)
Discussion started by: columb
1 Replies

10. UNIX for Dummies Questions & Answers

Easy About Bash Script function

Hi to all, first of all,i am working on MINIX 3 OS. I want to create a bash script file,which will create a list of files(not directories) that have been modified one specific day (i.e today) under my home directory. thank you very much!! :) (8 Replies)
Discussion started by: kostis1904
8 Replies
Login or Register to Ask a Question