General :: For Loop Or While Loop To Read The Fields Of A File?

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


Programming :: Read A File With A While Loop?

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

General :: Use A For Loop "access Fields" Or Awk?

Mar 17, 2011

I have a tab delimited file with 2 columns.

2224 23943843
5494 39843843
8372 48938384

I have to loop through this file and copy the files with the first field to a new name that contains both the first and second field. To be more specific, file quote2224.pdf has to be copied to 23943843_quote2224.pdf file quote5494.pdf has to be copied to 39843843_quote5494.pdf I don't know how or if it's even possible to use a for loop and access both fields. I don't know how to copy files in awk.

View 1 Replies View Related

Programming :: Bash - Read Content Of File To Variable And Use This Variable In For Loop ?

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:


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

General :: Redirect From A File Into An Actual For Loop?

Apr 11, 2011

I multi-boot several Linux distributions with an assortment of additional data partitions. I get frustrated whenever fsck is forced during boot. (It ONLY happens when I'm in a hurry don't you know...) So I wrote a script to automate forced fscking when I do have the time. (And/or while I'm doing something else in another workspace.

Because I multi-boot, I've learned that udev doesn't always assign the same device name to each drive for all distributions. I've had the same partition identified as hda5, sda5, & sdb5 by different distributions (without doing anything to affect the boot order) So my solution is to keep a list of partitions in a specific file on each distro with valid device names according to that distribution's udev process. Actually I'd use LABEL= instead but the labels don't show up in /etc/mtab, and I like to make sure a partition isn't mounted before I try to fsck it.

I can make this work in a for loop using cat. But I've seen so many things about NOT using cat that I wanted to rebuild my script. I can make this work with a redirect instead of cat via a while loop, But I "LIKE" old style for loops. But I can't seem to find a way to make a redirect work with one. I thought this might make a good first �� question. I'm also open to any other suggestions on better/alternative methods... Is it possible to redirect from a file into an actual for loop?

My script is as follows:


# FsckEm I script to force file system checking on unmounted ext2/ext3/ext4
# partitions in preselected list. FsckEm accepts no options. Partition


View 5 Replies View Related

General :: Create A New Background Process In A KSH "while Read" Loop?

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
while read -r line ; do


View 1 Replies View Related

Programming :: While Read Line - Doesn't Work With Ssh In The Loop Body

Mar 26, 2010

I am trying to read the names of hosts from a file and do a ssh to see if processes are all running or not.

Here is the outer loop that is causing problem:

hosts.lst is a text file that has the host names in each line.

The problem is that the loop just breaks after the first run. Somehow while read line becomes invalid when the body of the loop does the ssh and returns.

View 5 Replies View Related

General :: "read" Is Reading Info From While Loop?

Feb 10, 2011

I'm trying to prompt the user to enter Y or N in the middle of a while loop, but the read command is simply drawing in the next value.I'm reading from a simple file full of words (one per line)

while read line


View 1 Replies View Related

General :: How To Loop A Script Execution With Param From A Text File

Aug 14, 2010

I need to run ./pythonScript keyword one time for each keyword in a text file, how can I do this from a gnome terminal? (without having to modify the pythonScript)

pseudo code:

for each keyword in file:
./pythonScript keyword
waitfor(pythonScript to finish)

View 3 Replies View Related

Programming :: Loop Through Records In A File?

Apr 23, 2011

I want to loop through the records in the below file (homedir.temp)

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

Programming :: Fortran How To Open A File In Loop

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

Programming :: Take A List From A File And Use It In A For Loop In Python?

May 11, 2009

so far I have this

list = open('list.txt')
for x in list:

View 3 Replies View Related

Programming :: Loop To Process Entries In A File?

Jul 9, 2010

I hade created a file with following text entries.

content of fileitems.txt

How do I read the file one line at a time and so its ready to do something with that line.

View 3 Replies View Related

Programming :: Read Two Files Word By Word At A Time Using Any Loop By Shell Script?

Mar 4, 2010

Well, I am facing one issue:How can i read two files word by word at a time using any loop as i need word by word comparision in shell script?Please let me know pseudo code.

View 14 Replies View Related

Software :: VIM Runs Into An Indefinite Loop While Editing A Large File?

Apr 12, 2011

May I ask that does VIM support editing large files. I'm editing a 3G (good, less than 4G) text file with several millions of lines. I have deleted the first ~110,000 lines and :x (save and exit). OMG: this operation takes more than 3 days. I think it hangs already, so I terminated it. So my question is, can VIM do this???

Mine is:
VIM - Vi IMproved 7.0
Included patches: 1, 3-4, 7-9, 11, 13-17, 19-26, 29-31, 34-44, 47, 50-56, 58-64, 66-73,


View 1 Replies View Related

Programming :: Save The Results Of A Fortran Loop In A Text File?

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).

for (( i=1; i<=5; i++))
./file.exe > output.txt

View 2 Replies View Related

Ubuntu :: Mount Iso File - ERROR: Modinfo: Could Not Find Module Loop

Dec 4, 2010

I'd like to mount an iso file ,however, it failed as following: ljk@ljk-laptop:~/Test$ modinfo loop ERROR: modinfo: could not find module loop what I can do?

View 1 Replies View Related

General :: Cd Error From For Loop?

Nov 10, 2010

./ line 3: syntax error near unexpected token `cd'
./ line 3: `cd $f'


View 1 Replies View Related

General :: Syntax Error In If Loop?

Mar 7, 2011

I have a requirement to check the following conditions..If my folders are not A and B then list files in the directory else no listing the filesso my if loop is some thing like this.

if [ $dirName = "C" && $dirName != "A" && != "B" ] then
ls -la


View 1 Replies View Related

General :: Bash For Loop Not Working?

Apr 21, 2010

I have bash 4.0. I used the following for loop example, but all it outputs is "{1..10} instead of the actual numbers one through ten. why?

for a in {1..10}
echo -n "$a "

View 5 Replies View Related

General :: Using 'find' And 'grep' In A For Loop?

Mar 23, 2011

I have a server hosting 100+ websites. I need to quickly identify which websites are configured with a database. There are way too many to manually check every website for a PHP file with a database name. So, I created a list of all databases from MySQL and put them in a text file. I then exported the text file to a shell variable and used it in a for loop.

bash variable

DBLIST=`cat dblist.txt`
Example of $DBLIST

db1 db_testing2 database_clientname production words4cheap
for loop

for db in $DBLIST; do find . -type "f" -iname "*.php" -exec grep -i $db '{}' ; -print; done
Note: my find statement starts searching at . which is the directory that contains all of my websites and their data, each website is setup in a sub directory, identified by it's domain name.

Example: I'm in /var/www. Beneath /var/www are a list of directories:


However, this is taking too long (it's been running most of the day) and I was wondering if there wasn't an easier way to accomplish what I'm trying to achieve?

View 4 Replies View Related

General :: Cannot Add Fractions In Loop Using Bc In A Script?

Feb 11, 2010

i have tried a lot to add floating values in while loop using bc, but no sucess!!!

script is :
read a1
read a11


View 5 Replies View Related

General :: Shell Programming Using While Loop

Jun 28, 2010

I am trying to do some shell programs. I tried some sites regarding the while loop, they give the structure as:
while [ n1 -lt 500 ]
echo $((n1+100))

But the below code also worked for me:
while ((n1 > 500))
echo $((n1+100))
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

General :: Loop Detected When Resolving The Name From Dns?

Apr 26, 2010

The problem of loop detected when resolving the name from dns.Why the problem of loop detected comes when name is resolving from dns.

View 4 Replies View Related

General :: Getting The While Loop To Execute In The Ssh Command?

Jun 15, 2011

I am having trouble getting the while loop to execute in the ssh command:ssh $USERID@serverX "while read line do echo $line done<$list_dir/cost_feed.lst.old"Error:bash: -c: line 1: syntax error: unexpected end of fileI have managed to use simpler commands with ssh like:ssh $USERID@serverX "pwd; cp x y"I expect that I need to add some combination of escape characters or semicolons

View 3 Replies View Related

General :: Convert An Animated GIF (only Two Pics In Loop) To FLV / AVI?

Jan 31, 2010

Do you know how to convert an animated GIF (only two pics in loop) to FLV or AVI?

I didn't search for a Microsoft alternative that maybe could run with WINE, because I really prefer a native one; also a java version will be fine.

View 3 Replies View Related

General :: How To Break A Symbolic Link Loop

Feb 2, 2010

While I was trying to compile a C shared object library, I accidentally created two symbolic links which point to each other. Is there a way to get rid of them without nuking the whole directory? I read that the only way to break a symbolic link is to delete the file it points to, but I'm sure there must be another way.

View 3 Replies View Related

General :: Can't `mount -o Loop` An ISO From An NFS Share (RHEL)?

Jun 16, 2010

I have a large NFS share with a variety of software ISOs on it. I've only tried this on Red Hat Enterprise Linux, but when trying to do the following, the mount comes back with an error indicating no permissions to mount. Why would this be happening?NFS is mounted thusly:mediaserver:path/to/isos /media/nfsThis is the mount call that failsmount -o loop /media/nfs/product.iso /tmp/productIf I copy the ISO, there is no issue. The NFS share is mounted rw.How can I loop mount the ISO from the NFS share without copying it first?

View 2 Replies View Related

General :: Convert An Animated GIF (only Two Pics In Loop) To FLV Or AVI?

Jul 31, 2010

how to convert an animated GIF (only two pics in loop) to FLV or AVI? I didn't search for a Microsoft alternative that maybe could run with WINE, because I really prefer a native one; also a java version will be fine.

View 1 Replies View Related

General :: Recursively Browse Subfolders In A For Loop?

Feb 19, 2010

I wrote a script for copying mp3 files to my girlfriend's mp3-player and it looks like this:

mount /dev/sdc /test -o sync
for i in *.mp3; do


View 13 Replies View Related

Copyrights 2005-15, All rights reserved