Appending file in the read mode.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Appending file in the read mode.
# 1  
Old 02-25-2007
Appending file in the read mode.

I have situation, wherein while reading the file, I intend to write the same file & loop ahead until the end of file.

Problem I am facing is I can only read the file. Like ...

cat file | while read row; do
....
done


So if I write anything to this file within while block, is not read within this same while loop.

Is there any way, or construct so I can achieve Append the file during read process?
# 2  
Old 02-25-2007
Quote:
Originally Posted by videsh77
I have situation, wherein while reading the file, I intend to write the same file & loop ahead until the end of file.

Problem I am facing is I can only read the file. Like ...

cat file | while read row; do
....
done


So if I write anything to this file within while block, is not read within this same while loop.

Is there any way, or construct so I can achieve Append the file during read process?
Code:
cat file | while read row; do
....
done >> file

# 3  
Old 02-26-2007
Say initially file has values like :

A
B

If I append the same file with values :
C
D

Then I expect it will loop A, B, C, & D values. Though it is appending to the same file, it is not looping values C & D.

It is something like in JAVA, you have data structure as vector. You can iterate & populate at the same time. So in iteration, you can as well iterate the recently added value.

Last edited by videsh77; 02-26-2007 at 02:53 AM..
# 4  
Old 02-26-2007
this should iterate the recently added value. but make sure that you add a condition in the while loop to exit or else it might go to infinite loop. Might be you could add a counter variable to exit after running the loop for specific number of times.

Code:
while read fname ; do
echo x >>$filename
 done <$filename

# 5  
Old 02-26-2007
Great, seems working. Thanks Ahmed.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. HP-UX

From a C++ application how to find if a hpux host is in standard mode or trusted mode

is there a way for my C++ application to find out which mode the hpux OS is running in? standard mode or trusted mode. (3 Replies)
Discussion started by: einsteinBrain
3 Replies

2. Solaris

DNS service is in maintenance mode. How to bring it back to online mode?

:confused: when i tried to look the status of DNS-client, it is in maintenance mode..... Please tell me how to bring it back to online mode...PLEASE TELL ME STEP BY STEP.... PLEASE... :wall: (2 Replies)
Discussion started by: vamshigvk475
2 Replies

3. Shell Programming and Scripting

Ascii Mode appending extra records to csv file

I am relatively new to this forum and Unix scripting. ksh script: part 1 :will call a PL\SQL program will create 3 CSV file at the unix directory. part 2 : will sftp the files to the EFT server. Once the EFT server receives these file , it will transfer them to a shared windows folders. ... (3 Replies)
Discussion started by: developerpa
3 Replies

4. Shell Programming and Scripting

Removing part of a file name and appending into a single file

I have two files like ABC_DEF_yyyyymmdd_hhmiss_XXX.txt and ABC_DEF_yyyyymmdd_hhmiss_YYY.txt. The date part is going to be changing everytime. How do i remove this date part of the file and create a single file like ABC_DEF_XXX.txt. (8 Replies)
Discussion started by: varlax
8 Replies

5. UNIX for Advanced & Expert Users

What is the difference between single line mode and multiline mode in Regular expressions?

Hi All, Can please let me know what is the difference between the single line mode and multi line mode in regular expresions? Thanks, Chidhambaram B (3 Replies)
Discussion started by: chidhu.anu
3 Replies

6. Solaris

urgent: single-user-mode, /var/tmp read-only

this is the situation: Power outage. Root mirror (svm). it goes to single-user-mode, asking for fsck. Fsck suceeds for one disk, but fail for the other. I can't use vi-editor, it says /var/tmp/Xz12a is a read-only file system. I need to break the mirror, there's no copy of... (2 Replies)
Discussion started by: Sun Fire
2 Replies

7. SCO

file system not getting mounted in read write mode after system power failure

After System power get failed File system is not getting mounted in read- write mode (1 Reply)
Discussion started by: gtkpmbpl
1 Replies

8. Shell Programming and Scripting

searching a log file and appending to a .txt file

I'm new to shell scripting and am writing a script to help me log the free memory and hd space on a server. As of now, the script just runs 'df -h' and appends the output to a file and then runs 'top' and appends the output to a log file. What I want to do, is have the script also search the... (3 Replies)
Discussion started by: enator45
3 Replies

9. Solaris

Can't read floppy and cdrom in single user mode

I am having trouble reading floppy and crom in single user mode. running volcheck doesn't do anything I am using Solaris -10 on Sun blade 150. Has anybody seen this problem .. or do I have to manually mount the cdrom ...and floppy ??? thanks (2 Replies)
Discussion started by: ajnabi
2 Replies

10. Shell Programming and Scripting

Reading specific contents from a file and appending it to another file

Hi, I need to write a shell script (ksh) to read contents starting at a specific location from one file and append the contents at specific location in another file. Please find below the contents of the source file that I need to read the contents from, File 1 -----# more... (5 Replies)
Discussion started by: dnicky
5 Replies
Login or Register to Ask a Question