Reading sequentail file having commands


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Reading sequentail file having commands
# 1  
Old 07-21-2005
Reading sequentail file having commands

Hi,
Can some tell me how can i read a file sequentially i.e one line after other , which contains list of commands.

For ex :
My src_file looks like

awk -F:"-" '/abc/ {print $1}
awk -F:"-" '/zzz/ {print $1}
awk -F:"-" '/ppp/ {print $1}

I tried with for loop like this,

for i in `cat src_file`
do
echo $i
done

Since for loop take evry space as an entry, my output breaksup at every space & shows like
awk
-F:"-"
'/abc/
{print $1}
...
..
however my required output is awk -F:"-" '/abc/ {print $1}

Can someone throw some light ??

Thanks
Brian
# 2  
Old 07-21-2005
Code:
#!/bin/ksh

while read line
do
  echo $line
done < src_file

# 3  
Old 07-21-2005
yes that would surely work... put it in while loop... to be presice.. if the file name is abc.txt.. it will look like..
cat abd.txt | while read line
do
echo $line
done

and in the loop you can do what ever you want with the line.... like cut etc !!....
# 4  
Old 07-21-2005
that was typo !!... :-o) typed abd.txt instead of abc.txt.....

cat abc.txt | while read line
do
echo $line
done
# 5  
Old 07-21-2005
Quote:
Originally Posted by rosh0623
that was typo !!... :-o) typed abd.txt instead of abc.txt.....

cat abc.txt | while read line
do
echo $line
done
this is a UUOC - don't 'cat' through the pipe - use 'file redirection'.

Last edited by vgersh99; 07-21-2005 at 08:05 PM..
# 6  
Old 07-22-2005
Hi,
Thanks a lot for your inputs,It worked,but i just got into another problem
now my script looks like

Code:
     1 #!/bin/ksh
      2 #set -x
      3 cd $PM_HOME/Scripts
      4
      5 while read ln
      6 do
      7 echo "VALUE IS : $ln"
      8 v1=`cut -f3 -d";"`
      9 echo $v1
     10 v2="$v1"
     11 echo $v2
     12 done < test.in
~

and my input file test.in looks like

HTML Code:
XXX;111;`du -c $PM_HOME/SrcFiles/[A,a][c,C][s,S][!_]*| awk '/total/ {print $1}'`
yyy;222;`du -c $PM_HOME/SrcFiles/[A,a][c,C][s,S][!_]*| awk '/total/ {print $1}'`
As mentioned before, my objective is read every line of the file contains commands, then execute it & then store it a variable.

However, I'm unable to execute the command, it's just stores it as string, inspite I've included backquotes in the sourcefile. Any reasons why ?
# 7  
Old 07-22-2005
don't need the back-quotes in the file, but just in case you do have them - I remove them
not tested........
Code:
#!/bin/ksh

while IFS=';' read foo foo cmd
do
  cmd=$(echo ${cmd} | sed 's/`//g')
  echo "cmd->[${cmd}]"
  var=eval ${cmd}
  echo "var->[${var}]"
done < test.in


Last edited by vgersh99; 07-22-2005 at 09:16 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh Script, Reading A File, Grepping A File Contents In Another File

So I'm stumped. First... APOLOGIES... my work is offline in an office that has zero internet connectivity, as required by our client. If need be, I could print out my script attempts and retype them here. But on the off chance... here goes. I have a text file (file_source) of terms, each line... (3 Replies)
Discussion started by: Brusimm
3 Replies

2. UNIX for Dummies Questions & Answers

Reading Xml file and print the values into the text file in columnwise?

hi guys, i want help... Reding XML file and print the values into the text file using linux shell script file as per below xml file <sequence> <Filename>aldorzum.doc</Filename> <DivisionCode>US</DivisionCode> <ContentType>Template</ContentType> <ProductCode>VIMZIM</ProductCode> </sequence>... (4 Replies)
Discussion started by: sravanreddy
4 Replies

3. Shell Programming and Scripting

Reading ls -l output line by line awk the user name and su user to run commands

Using ksh on AIX what I am trying to do is to read the ls -l output from a file in a do while loop line by line. Extract the user name(3rd field) and the directory/file name(9th field) using awk and save them into variables. su -c to the user and change directory/file permisions to 777. Script I... (13 Replies)
Discussion started by: zubairom
13 Replies

4. Shell Programming and Scripting

Reading UNIX commands from file and redirecting output to a file

Hi All I have written the following script: #!/bin/ksh while read cmdline do echo `$cmdline` pid="$cmdline" done<commands.txt =========== commands.txt contains: ps -ef | grep abc | grep xyz |awk '{print $2}; My objective is to store the o/p of the command in a variable and do... (8 Replies)
Discussion started by: rahulparo
8 Replies

5. Shell Programming and Scripting

Searching for Log / Bad file and Reading and writing to a flat file

Need to develop a unix shell script for the below requirement and I need your assistance: 1) search for file.log and file.bad file in a directory and read them 2) pull out "Load_Start_Time", "Data_File_Name", "Error_Type" from log file 4) concatinate each row from bad file as... (3 Replies)
Discussion started by: mlpathir
3 Replies

6. Shell Programming and Scripting

Help with shell script to run the commands reading options from local file

I have to use shell script to run series of commands on another unix box by connecting through SSH and giving user credentials. For running commands on remote machine I have to use options reading from a local file. Process: Connecting to remote unix server <host1.ibm.com> through ssh Login: ... (2 Replies)
Discussion started by: itsprout
2 Replies

7. Shell Programming and Scripting

Reading Commands From a File

I am trying to create a script that will read bash commands from a text file and execute them. These commands would all be defining variables. Is this possible, and if so, how do I do it. Any help would be greatly appreciated. (2 Replies)
Discussion started by: vockleya
2 Replies

8. Shell Programming and Scripting

bash: executing commands and reading exit vals

I have a function that returns a bunch of exit codes, say func1, and in my code I'm trying to execute that function in an if statement. This is the closest I could get. f1call=`func1 $arg1 $arg2` if ]; then ... fi When I run the script the function never gets called. What's the right way... (7 Replies)
Discussion started by: eur0dad
7 Replies

9. Shell Programming and Scripting

Reading file names from a file and executing the relative file from shell script

Hi How can i dynamically read files names from a list file and execute them from a single shell script. Please help its urgent Thanks in Advance (4 Replies)
Discussion started by: anushilrai
4 Replies
Login or Register to Ask a Question