Please help me in taking the values from a file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Please help me in taking the values from a file
# 1  
Old 08-07-2008
Question Please help me in taking the values from a file

i have a script, whcih takes values from a file and assign it to one variable. this text value contains name of few object. value contains line by lie. i.e. one after another.

when i am assaign the value of this text file to a variable, it accept the value as one liner instead of one by one. pls help me in this.


#!/bin/bash
exclude="`cat /tmp/excludejobs`"
echo $exclude > /tmp/testexclude
find /home/bosuser/Production/jil/* | xargs grep /home/bosuser|cut -d "." -f1|cut -d "/" -f6|uniq > /tmp/includejob
job="`cat /tmp/includejob`"
echo $job > /tmp/testinclude

for i in $job
do

if [ $i != $exclude ]
then
anjil -sd $job > /tmp/document
cat /tmp/documnet | grep 'Team Mail Alias' > /tmp/rawmail
cat /tmp/rawmail | cut -d ":" -f2 > /tmp/mailalias
/usr/ucb/mail -s "notification" xx@yyyyy.com
fi


here the value takes as one liner instead of one by one.

in csh sheel we have "foraech" command but in bash how can i fullfill this

Last edited by DukeNuke2; 08-07-2008 at 02:23 AM.. Reason: changed email
# 2  
Old 08-07-2008
Just replace follwing line in your program and it should work.

Code:
echo "$exclude" > /tmp/testexclude
echo "$job" > /tmp/testinclude

One suggestion, Use less number of files, pipes and shell commands in script. This will help to improve performance of your script.

If this also doesnt work please let me know Smilie
- nilesh
# 3  
Old 08-10-2008
Question how to take a value which comes above the search string

tht has been resolved.. any way thaks for your reply. i have another query.

I have a file , which having the following out put

insert_job: PS_PositivePayBox job_type: b
insert_job: PS_PositivePay_MOBox job_type: b
insert_job: PS_PositivePay_MO_norun job_type: c
owner: bosuser

insert_job: PS_PositivePay_MO_Watch job_type: f
insert_job: PS_Wait_MO job_type: c
owner: bosuser

insert_job: PS_Fetch_MO job_type: c
insert_job: PS_Notify_MO job_type: c
owner: bosuser

insert_job: PS_PositivePay_BWBox job_type: b
insert_job: PS_PositivePay_BW_norun job_type: c
owner: bosuser
insert_job: PS_PositivePay_BW_Watch job_type: f

I need to find all the insert_job line, which comes above owner: bosuser

For eg.

insert_job: PS_PositivePay_BW_norun job_type: c
owner: bosuser

I need the , “ insert_job: PS_PositivePay_BW_norun job_type: c”

What can be the command
# 4  
Old 08-11-2008
Use,
Code:
grep -B 1 "owner: bosuser" {filename}

Output will same like what you want,
Quote:
insert_job: PS_PositivePay_MO_norun job_type: c
owner: bosuser
--
insert_job: PS_Wait_MO job_type: c
owner: bosuser
--
insert_job: PS_Notify_MO job_type: c
owner: bosuser
--
insert_job: PS_PositivePay_BW_norun job_type: c
owner: bosuser
- nilesh
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Taking key values from one file and extracting values from another file

Hi, I have two files with values in both. File1: cat 2 3 dog 4 5 elephant 6 7 camel 2 3 File2: ----+--gkf;ajf= ---+---- +----- cat -------=----+ 3 | 4 ----- dog ------++-- 5 | 9 ----++-- elephant | 5 | 7 ---++ camel ------ ++++_---- || 8 | 9 I want the final file as: cat 4... (1 Reply)
Discussion started by: npatwardhan
1 Replies

2. Shell Programming and Scripting

Search pattern in a file taking input from another file

Hi, Below is my requirement File1: svasjsdhvassdvasdhhgvasddhvasdhasdjhvasdjsahvasdjvdasjdvvsadjhv vdjvsdjasvdasdjbasdjbasdjhasbdasjhdbjheasbdasjdsajhbjasbjasbhddjb svfsdhgvfdshgvfsdhfvsdadhfvsajhvasjdhvsajhdvsadjvhasjhdvjhsadjahs File2: sdh hgv I need a command such that... (8 Replies)
Discussion started by: imrandec85
8 Replies

3. Shell Programming and Scripting

Replace from taking from file

Hi, I have one file. S_CHAR.cfg. Content given below. \" abcd1234 \| abcd1235 \$ abcd1236 So it has two record per line delimited by space. No I am looking for some help on how to replace this special charaters ( mentioned in record 1 of each line) with the values mentioned in... (7 Replies)
Discussion started by: Anupam_Halder
7 Replies

4. UNIX for Dummies Questions & Answers

Taking word count from file and printing in file

hi, i am having a file which contains the below content, i need to take the word count of if and print the file name also inputfile.txt file_name1.txt,type_name1.txt file_name2.txt,type_name2.txt i would need the word count of the files like this if file_name*.txt then wc -l... (10 Replies)
Discussion started by: rohit_shinez
10 Replies

5. Shell Programming and Scripting

Installing a bin file by taking input from a properties file

I need to install a bin file in UNIX which requires user interaction for giving some information like user id , path, sid etc. All these information is stored in a properties file in the same location. So if i give ./file.bin -f propfile.properties will it install the file taking all the... (1 Reply)
Discussion started by: coolmohere
1 Replies

6. Shell Programming and Scripting

Taking sum up all values inside the file

Hi, Taking sum up all values inside the file by using the below command: paste -sd+ filenmae | bc Getting some error like "0705-001: building space exceeded on line1 stdin" The original data looks like SPACE SPACE SPACE 0.123 JOBNAME1 SPACE SPACE 20.325 JOBNAME2 SPACE SPACE... (2 Replies)
Discussion started by: NareshN
2 Replies

7. Shell Programming and Scripting

How to ftp multiple files by taking the file name from a input file.

Hi, I'm working on a script which has to copy multiple files from one server to another server. The list of files that are to be copied is present in a file say input.txt. vi input.txt abc.c welcome.c new.c welcome1.c for ftp'ing a single file say 'new.c' the following code... (2 Replies)
Discussion started by: i.srini89
2 Replies

8. Shell Programming and Scripting

taking the Log2 values

Hi, I am able to take the log value for the third column of a file using the script below. But I want to take the log2 (not the log). How would I write that? thanks awk 'BEGIN {OFS="\t"} {print $1, $2, log ($3)}' (2 Replies)
Discussion started by: kylle345
2 Replies

9. Shell Programming and Scripting

Taking a particular attribute's value in a file...

HI, Iam new to scripting..I need some guidance for invoking the following logic.. My input file contains Event Time = Thu, Nov 6, 2008 08:41:56 AM Probable Cause = UnspecifiedReason Specific Problems = BTS down due to Tx ... (16 Replies)
Discussion started by: Llb
16 Replies

10. Shell Programming and Scripting

taking a part from file name

hi i have a file with name "CT_Thread_Trace.384.20080728-121217.log" i need 384 , can any one help thanks Satya (5 Replies)
Discussion started by: Satyak
5 Replies
Login or Register to Ask a Question