Process one line at a time


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Process one line at a time
# 1  
Old 08-12-2008
Process one line at a time

Guys,

I've written the following to proces one line at a time and then process individual column within the line.. But it works only when there is one line. I know awk will simply fetch multiple lines when run against a file with many lines. How do i achieve this ?




cat ${PARFILE} | while read line
do
DBID=`awk '{print $1}' $line`
USERID=$(${ORACLE_BASE}/getpass.ksh SYS ${DBID})
echo userid is $USERID
TSNAME=`awk '{print $2}' $line`
echo tablespace is $TSNAME
runSql "${USERID}" "${TSNAME}"
echo $COUNT

THRESHOLD=`awk '{print $3}' $line`
echo Threshold=$THRESHOLD
if [[ $COUNT -lt $THRESHOLD ]]
then
DIFF=`expr $THRESHOLD - $COUNT`
echo "Diff is $DIFF"
MSG="Please add ${DIFF} Mb to tablespace ${TSNAME} on ${DBID}"
echo $MSG >> /tmp/ts_add.out
fi

done






The parfile is

strd1.uk.ml.com STR_DATA 2180
strp2.uk.ml.com STR_INDEXES 900
strp2.uk.ml.com STR_LOB_DATA 500
ukpp1.uk.ml.com SAMBA_DAT 800


Thank you
# 2  
Old 08-12-2008
All that i am trying to do is display individual column values for each line and something with it

10.2.0> cat .TS_DETAILS | while read line
> do
> echo $line
> echo `awk '{print $1}' ${line}`
> done
strd1.uk.ml.com STR_DATA 2180
awk: cmd. line:2: fatal: cannot open file `strd1.uk.ml.com' for reading (No such file or directory)

strp2.uk.ml.com STR_INDEXES 900
awk: cmd. line:2: fatal: cannot open file `strp2.uk.ml.com' for reading (No such file or directory)

strp2.uk.ml.com STR_LOB_DATA 500
awk: cmd. line:2: fatal: cannot open file `strp2.uk.ml.com' for reading (No such file or directory)

ukpp1.uk.ml.com SAMBA_DAT 800
awk: cmd. line:2: fatal: cannot open file `ukpp1.uk.ml.com' for reading (No such file or directory)
# 3  
Old 08-12-2008
Use as.
Code:
echo $line | awk '{...}'

# 4  
Old 08-12-2008
shamrock.. Many thanks for your help.. Much appreciated
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script to read a file from particular line till required line and process

Hi All, Am trying to write wrapper shell/bash script on a utility tool for which i need to pass 2 files as arugment to execute utility tool. Wraper script am trying is to do with above metion 2 files. utility tool accepts : a. userinfo file : which contains username b. item file : which... (2 Replies)
Discussion started by: Optimus81
2 Replies

2. UNIX for Dummies Questions & Answers

Parsing file, reading each line to variable, evaluating date/time stamp of each line

So, the beginning of my script will cat & grep a file with the output directed to a new file. The data I have in this file needs to be parsed, read and evaluated. Basically, I need to identify the latest date/time stamp and then calculate whether or not it is within 15 minutes of the current... (1 Reply)
Discussion started by: hynesward
1 Replies

3. Shell Programming and Scripting

Shell script to read a text file line by line & process it...

Hi , I am trying to write an shell, which reads a text file (from a location) having a list of numbers of strictly 5 digits only ex: 33144 Now my script will check : 1) that each entry is only 5 digits & numeric only, no alphabets, & its not empty. 2)then it executes a shell script called... (8 Replies)
Discussion started by: new_to_shell
8 Replies

4. Shell Programming and Scripting

How to calculate time difference between start and end time of a process!

Hello All, I have a problem calculating the time difference between start and end timings...! the timings are given by 24hr format.. Start Date : 08/05/10 12:55 End Date : 08/09/10 06:50 above values are in mm/dd/yy hh:mm format. Now the thing is, 7th(08/07/10) and... (16 Replies)
Discussion started by: smarty86
16 Replies

5. UNIX for Advanced & Expert Users

how do you parse 1 line at a time of file1 ie. line(n) each line into new file

File 1 <html>ta da....unique file name I want to give file=>343...</html> <html>da ta 234 </html> <html>pa da 542 </html> and so on... File 2 343 234 542 and so on, each line in File 1 one also corresponds with each line in File 2 I have tried several grep, sed, while .. read, do,... (4 Replies)
Discussion started by: web_developer
4 Replies

6. Linux

Process start time not showing correct time

Process start time is not showing the correct time: I had started a process on Jun 17th at 23:30:00. Next day morning when I run the command "ps -ef | grep mq", the process is showing the start date of Jun 17th but the start time is 00:16:41 Day/Date is setup correctly on the server. It... (2 Replies)
Discussion started by: hemangjani
2 Replies

7. UNIX for Advanced & Expert Users

Process accounting and Shell process time

Hi All, I am running the following accounting on one of my executable, $ accton /home/myexe-acct $ ./myexe $ accton When I check the process timings I get the below result, Shell process time: 300ms myexe time: 100ms I want to know on why the shell(sh) process is taking so much time... (1 Reply)
Discussion started by: santoshbr4
1 Replies

8. Shell Programming and Scripting

How to read/process a .gz file, one line at a time?

Hello I'm stuck trying to solve this KSH issue and I'm hoping someone out there can offer some suggestions. I want to read lots of large .gz files one line at a time in order to compare its Error entries with a list of known errors. I can't simply do "foreach ERROR do gzcat *.gz |grep... (2 Replies)
Discussion started by: dayscripter
2 Replies

9. UNIX for Dummies Questions & Answers

shell script to process file line by line

Hi , I am new to shell scripting (ksh shell) and trying to accomplish few requiremtns. I have a file with the following format EMP NO EMP NAME AGE Amt Paid 12 Mark Taylor 32 32333 14 James Brown... (5 Replies)
Discussion started by: royalsing
5 Replies

10. UNIX for Dummies Questions & Answers

how to Decrease priority of a particular process in time of process creation

how to decrease priority of a particular process in time of process creation... and also how to decrease priority of a particular process after process creation.. can any one please help me out... (2 Replies)
Discussion started by: Ramkum
2 Replies
Login or Register to Ask a Question