Programming :: Loop To Process Entries In A File?
Jul 9, 2010
I hade created a file with following text entries.
content of fileitems.txt
kdeaccessibility-4.4.92
kdeadmin-4.4.92
kdeartwork-4.4.92
kdebase-4.4.92
How do I read the file one line at a time and so its ready to do something with that line.
View 3 Replies
ADVERTISEMENT
Apr 23, 2011
I want to loop through the records in the below file (homedir.temp)
/home/user1
/home/user2
/home/user3
I want to do the following activities with each record1. du -s - to get the total usage for that directory (my variable name is SIZE)2. divide SIZE by du -c for /home to get the percentage of usage. (my variable name is PER)3. write the directory, SIZE, PER to a filePROBLEMI am using the below for loop: for record in homedir.tempthe mentioned activitiesdonehe above is not looping through the records. It does the first record perfectly and exits the loop.
View 14 Replies
View Related
Apr 25, 2010
ITT and am just lurning about scripting and need to read a file and output the file to the screen. We need to do this with a while loop.
View 5 Replies
View Related
Jun 29, 2011
I have a 50 file name NSSAVE0001.vtk to NSSAVE0050.vtk.Do I have to manually type individually command to open each file or can I have a loop to open file?
View 3 Replies
View Related
May 11, 2009
so far I have this
list = open('list.txt')
for x in list:
list.read(x)
View 3 Replies
View Related
Nov 2, 2010
I am trying to store the results of my code to a separate text file.But the problem is, as my results comes from a loop, my text file shows only the last result, not all of them.Like if the loop runs 5 time the text file shows the result for the 5th step.But i need to store all of them (1 to 5).Can I use awk to print the output field and store to another file and creat a new line so that the next output field goes to a new line?(just an idea, dont know).
#!/bin/basth
for (( i=1; i<=5; i++))
do
./file.exe > output.txt
done
View 2 Replies
View Related
Sep 1, 2010
I have a mytext file with month and year as two separate fields. likemytext fil
08 2010
09 2010
10 2010
........
........
........
I want to read the values of each field i.e., month and year into an awk script.
View 10 Replies
View Related
Apr 1, 2011
I am trying to develop a process monitor, or use existing monitors to achieve the below given actions.
1) Restart a processes if it crashes.
2) Restart a processes if it is stuck in an infinite loop.
The sample code below describes the structure of the process.
while(1)
{
statement 1....
statement 2....
while (1)
{
[Code].....
The goal is to restart the process if it is stuck in a loop, inside the outer while loop. Given this scenario, what would be the most efficient way to monitor such a process?
A sample solution would look something like this: statement 3 will write to file1 every time it is executed and we know that the maximum execution time of the outer while loop is 30 seconds. A second, timer driven process, checks for file1 being modified every 30 seconds. If the file is not modified, process 1 will be restarted assuming, process1 is stuck in a while loop.
View 2 Replies
View Related
Aug 21, 2009
I'm trying to read content of file to variable and use this variable in for loop. The problem is, when I have c++ comment style in file - /*. Spaces in line are also interpreted as separated lines.
For example:
Code:
Changing $files to "$files" eliminate these problems but causes that whole content of variable is treated as one string (one execution of loop).
View 6 Replies
View Related
Jan 4, 2011
I have a script can process input text file and find out 3 values called positive, negative, neutral. Now, I have a new input file which contains some text called 'content' and I need to use the above script to get three value positive, negative, neutral for each of this 'content'. The content is text in many lines and bounded by two tags <content> and </content>
The input file could have this format:
<example>
<input>
<id>abcdef</id>
<content> line1
line 2
[Code].....
Do you think that is possible to write that in Linux ? I have the feeling that using Linux with text finding, replacing much shorter and easier(when I have to write long and complicated code in other languages), so really want to learn how to use it from here.
View 14 Replies
View Related
Oct 26, 2010
I need to process a log file on an hourly basis but the log only rotates once a day.Basically, I am trying to get the difference between the previous file and the current file based on datetime. ie. The new file's datetime events > previous file's datetime events.The first field in the files is datetime.
Code:
2010-10-27 01:57:32,aaa.bbb.ccc.ddd,host1
2010-10-27 01:57:32,aaa.bbb.ccc.ddd,host2
[code]...
View 4 Replies
View Related
Feb 16, 2010
I am working in HP UNIX. I have one process which is running continuously.There is log file generated for the process. I want to take back up of file without loosing any logs after particular interval of time or say file size increases more that 1GB.
View 3 Replies
View Related
Mar 8, 2011
I need to disable file access (fopen, freopen, open etc) for application which is running under chroot jail and with restrictions (rlimit) via execv. Before that I redirected stdin/out to files within jail. I tried this:
Code:
// Redirect stdin/stdout to files
int fd = open (file_input, O_RDONLY);
if (fd < 0)
fatal_error ("input open failed!");
[Code].....
View 6 Replies
View Related
Mar 31, 2011
I need to rename the resulted searched files from a loopI have the following code:
find . -name DOC* | while read i
do
find $i -type f -name '*.txt'
done
basically, I am searching for all txt files inside any folder starting with DOC name.this code is working fine with me.I need to rename those .txt files to .txtOLDOS: Ubuntu 10.4Bash shell
View 10 Replies
View Related
Nov 9, 2010
I have a shell script to identify whether the process is running or not. If the process is not running, then I execute another script file to run my application. Below is my script and saved this script as monitorprocess.sh Code: #!/bin/bash
result=$(ps -ef | grep -v grep | grep "applicationname.sh" | awk '{print $2}')
echo $result
if [ "$result" == "" ];
[code]...
View 4 Replies
View Related
Mar 31, 2011
Is there any difference in cpu usage for process in init.rc(runs automatic when boot is happened) and manually running process. Will these both have same priority by default...?
View 1 Replies
View Related
Nov 26, 2008
I tried googling but didn't get any answer for this.I have a process called "abc" and it is running with PID "123".I have a putty session opened with PID "999".I am giving kill -TERM 123 from putty session.My process "abc" before dying it should catch the PID of the terminal which provided TERM signal to it.Is there any way to find this out
View 2 Replies
View Related
Nov 11, 2010
I've some file with .sh extensions that runs some softwares.Now,how do I stop running that filesI know we run the command ./start_tomcat.sh to start the apache.Is there any command to stop that file/process or is it just kill the process to stop the process
View 2 Replies
View Related
Jun 20, 2010
When I add the line (sleep 5 ) & in the script then the "while read" loop does not read all lines from the file, but only prints the first line.But when I remove the ( sleep 5 ) & from the script, then the script prints all lines as defined in the file.And how to solve the problem? I want to create a new process (for which the sleep is just an example) in the while loop:
$ more test
#!/bin/ksh
while read -r line ; do
[code]....
View 1 Replies
View Related
Jan 8, 2010
one tell me the internal working of kill command. that is how it kills a process internally or from where it picks file to continue its process.
View 3 Replies
View Related
Nov 30, 2010
I have an inventory.txt file in CVS, which has about 5000 lines. First ten lines from inventory.txt are following:
Code:
Serial_Number Location
P303948932 Shelf:4F
F348237842 Shelf:2C
W312390232 Shelf:9L
Q239432042 Shelf:1E
[Code]...
View 1 Replies
View Related
Feb 9, 2011
i can not figure out why my program does not terminate if i type n when i read loop unless it is the last if statement in my program ?
while [ "$loop" = y ] ; do
echo "what does baket mean: " ; read word
if [ "$word" = why ]
[code]....
View 3 Replies
View Related
Oct 3, 2010
Here is my code
Code:
I just cant seem to understand loops. i havent put the loop in yet but what i would like is the user only to have 3 tries at guessing number then exit if wrong or it says "correct if right" tbh i dont even know if the above code is correct. i have tried several ways and position of the loops but each time is comes out wrong
View 7 Replies
View Related
Mar 25, 2011
I have a directory file capturing script, the variable is fine with in the loop but gone after the loop is done:
Code:
DIR="/usb/sdb1/media/music/"
i=1
[code]...
View 9 Replies
View Related
Nov 1, 2010
we have a variable LIBS:
LIBS='-lpq -lmysqlclient -lssl -lpthread -lresolv -lssl -lpthread -lresolv'
I'd want to get:
LIBS='-lpq -lmysqlclient -lssl -lpthread -lresolv'
Bear in mind that LIBS can be variable, I mean I need to drop any duplicate and only retain the last one of each different entry. And we must keep the order as is, I must not sort out them.
So, if LIBS is:
LIBS='-lpq -lmysqlclient -lpthread -lresolv -lpthread -lresolv'
I need: LIBS='-lpq -lmysqlclient -lpthread -lresolv'
View 3 Replies
View Related
Apr 24, 2010
I am about to move my scripts to the next generation level, so I need some help I am stuck in varying my variable names in a loop. For example:
for user in ben dorothy mike pat
do
[ -r /home/$user ] && let "$user"check=1 || let "$user"check=0
[code]...
View 1 Replies
View Related
Jun 28, 2010
I am trying to do some shell programs. I tried some sites regarding the while loop, they give the structure as:
Code:
while [ n1 -lt 500 ]
do
echo $((n1+100))
done
But the below code also worked for me:
Code:
while ((n1 > 500))
do
echo $((n1+100))
done
By using (( )) I could use while, for. But the documentations didnt follow this way. I mainly use this for datastructure programming.
View 4 Replies
View Related
Aug 1, 2010
In the code segment below is a for loop I am having some considerable difficulty with. It just keeps iterating endlessly and totally ignores the 70 times limit specified. I can't ever remember having this problem before and am absolutely Clueless.
Code:
for ( x = 0; x < 70; x++ )
{
fputs ("CSN00", target);
fprintf (target, "%d", userid);
[Code].....
View 14 Replies
View Related
Nov 3, 2010
I've got a 'nested' for loop which has a grep in it, if the grep fails there's no output - however the error code is still $0 and the second for loop is still entered, there's also a grep in the second for loop.I guess ultimately what i need to know is whether there's a way of making grep generate an error code. when no results are found?
View 14 Replies
View Related
Jan 12, 2014
What I would like to do is, with a right click, have the menu give me the option to run srm, which is a "secure remove" program. I picked this one as it requires not only a file name, but some other options. I've run into no support adding things to menus. When I updated one of the Debian versions, I lost the shutdown option from the name menu that used to be there. It was suggested that I right click and pick that option to restore it, but I get the same as the left button on that menu.
View 2 Replies
View Related