November 24, 2024, 04:41:18 PM

News : LinuxSolved.com Linux Help Community Forum..


Author Topic: Script writing in linux which can run a command on loop basis while taking input from a file  (Read 12317 times)

Offline omerbest

  • New Member
  • Posts: 2
Hi people,

I want to write a script on linux. I am dumping a real time file from my machine. Every time I dump the file, it stores a certain pattern of 32 character string in each line. The number of lines on every attempt of dumping the file could be different. A sample of a dumped file could be:

kjhas87asjaksiui3jhh9898i9isb361
kjhas87asjaksiui3jhh9898i9isb362
kjhas87asjaksiui3jhh9898i9isb363
kjhas87asjaksiui3jhh9898i9isb364

While on dumping the file again, it could be:

kjhas87asjaksiui3jhh9898i9isb365
kjhas87asjaksiui3jhh9898i9isb366

It means every time you dump the file you could have different number of lines and would have different pattern of 32 character string.

Now I wish to design a script which takes these lines (32 character string) as an input to a command as below:

cli call delete 32-character-string

It means the script runs the above command exactly the same time as of the total number of lines present in the dumped file. It could run as a loop, but every time those 32-character-string from each line should process with that command, unless the lines in the file are finished.

Please help me, or give me an idea to write such script.
Thanks in advance!

Offline gauravbajaj

  • LST CareTaker
  • Experienced
  • *****
  • Posts: 658
Take file names in one file and loop through it using for loop . In loop , cat each line of the filename and count no. of lines ( wc -l )  and in-turn create while loop which process exactly the above lines.
Lets say
j=0;
 for i in `filelist`
do
tlines=cat $i | wc -l;

while [ $j -le tlines ]
do
for s in `cat $i`
do
write your command here ( use $s instead of 32 char string)
done
done
done

I dont know if above will work or not. I didnt try it . It may contain syntax error . Its just a logic..