Sponsored Content
Top Forums Shell Programming and Scripting Unable to read the first space of a record in while loop Post 302605236 by machomaddy on Wednesday 7th of March 2012 03:31:09 AM
Old 03-07-2012
Unable to read the first space of a record in while loop

I have a loop like
Code:
while read i
do
echo "$i"
.
.
.
done < tms.txt

The tms.txt contians data like
Code:
2008-02-03 00:00:00
<space>00:00:00
.
.
.
2010-02-03 10:54:32

The above while loop reads the second as 00:00:00 instead of <space>00:00:00.Smilie

Can some one suugest me a way in which I can read the first space also.??
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

need to space fill a 2060 byte record

Calling all experts: When I ftp from Mainframe to unix server, the ftp message says fixed length 2060, but i lose trailing spaces. I tried a solution i found here, awk ' { printf("%-2060s\n",$0) } ' fname1 > fname2 works for small records but, err msg: string too long, for long records ... (1 Reply)
Discussion started by: JohnMario
1 Replies

2. UNIX for Dummies Questions & Answers

how to read record by record from a file in unix

Hi guys, i have a big file with the following format.This includes header(H),detail(D) and trailer(T) information in the file.My problem is i have to search for the character "6h" at 14 th and 15 th position in all the records .if it is there i have to write all those records into a... (1 Reply)
Discussion started by: raoscb
1 Replies

3. UNIX for Advanced & Expert Users

"while read ..." loop exiting after reading only one record

Greeting, The following script completes after reading only one record from the input file that contains many records. I commented out the "ssh" and get what I expect, an echo of all the records in the input.txt file. Is ssh killing the file handle? On the box "uname -a" gives "SunOS... (2 Replies)
Discussion started by: twk
2 Replies

4. Shell Programming and Scripting

printing space after a record in awk

friends, I am running iostat command in linux. Following is the output iostat -d Linux 2.6.18-128.el5 (btovm725.ind.hp.com) 04/16/2010 Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn sda 21.49 5.32 255.61 2871221 138010414 sda1 ... (8 Replies)
Discussion started by: achak01
8 Replies

5. Shell Programming and Scripting

Replace comma by space for specified field in record

Hi, i want to replace comma by space for specified field in record, i mean i want to replace the commas in the 4th field by space. and rest all is same throught the record. the record is 16458,99,001,"RIMOUSKI, QC",418,"N",7,EST,EDT,902 16458,99,002,"CHANDLER,... (5 Replies)
Discussion started by: raghavendra.cse
5 Replies

6. Shell Programming and Scripting

Update file record inside read loop

Hi, I am reading file records inside a while loop, and want to update the record when certain condition is met. How can I update a file while being read? I want to avoid using temporary files, copy, rename, ... while IFS=',' read -r f1 f2 do function(f1,f2) if then <add... (1 Reply)
Discussion started by: ysrini
1 Replies

7. Shell Programming and Scripting

How to remove space from each record in file?

Hi , I want to remove space from each record in one file My file is like BUD, BDL ABC, DDD, ABC ABC, DDD, DDD, KKK The o/p should be BUD,BDL ABC,DDD,ABC ABC,DDD,DDD,KKK Can any one help me regarding this? (9 Replies)
Discussion started by: jagdishrout
9 Replies

8. Shell Programming and Scripting

Unable to read assign values to two variables in while loop

I am trying to read a input file which has two columns separated by space Input file server1 server2 server3 server4 server5 server6 When i execute the below while code it reads line by line and a and b variables are able to successfully fetch the values while read a b do echo "$a" echo... (5 Replies)
Discussion started by: chidori
5 Replies

9. Shell Programming and Scripting

ksh while read loop breaks after one record - AIX

#!/bin/ksh for SRV in imawasp01 \ imawasp02 \ imawasp03 \ imawasp04 \ imawasp05 \ imawasp06 \ imawasp07 \ imawasp08 \ imawasp09 do print "${SRV}" while read PASSLINE do SRVNAME=`echo ${PASSLINE} | awk -F\: '{print $1}'` LASTLOGIN=`ssh ${SRV} lsuser ${SRVNAME} | tr '... (2 Replies)
Discussion started by: port43
2 Replies

10. Shell Programming and Scripting

Unable to read user input inside a loop

Hi, This query is a part of a much more lengthy script. I wish to look for all the files in a folder named "data" which in this case has two files i.e. plan.war and agent.properties. For all the files found under data I wish to ask the user as to where they wish copy the files to. Below,... (14 Replies)
Discussion started by: mohtashims
14 Replies
TIMES(2)						     Linux Programmer's Manual							  TIMES(2)

NAME
times - get process times SYNOPSIS
#include <sys/times.h> clock_t times(struct tms *buf); DESCRIPTION
times() stores the current process times in the struct tms that buf points to. The struct tms is as defined in <sys/times.h>: struct tms { clock_t tms_utime; /* user time */ clock_t tms_stime; /* system time */ clock_t tms_cutime; /* user time of children */ clock_t tms_cstime; /* system time of children */ }; The tms_utime field contains the CPU time spent executing instructions of the calling process. The tms_stime field contains the CPU time spent in the system while executing tasks on behalf of the calling process. The tms_cutime field contains the sum of the tms_utime and tms_cutime values for all waited-for terminated children. The tms_cstime field contains the sum of the tms_stime and tms_cstime values for all waited-for terminated children. Times for terminated children (and their descendants) are added in at the moment wait(2) or waitpid(2) returns their process ID. In par- ticular, times of grandchildren that the children did not wait for are never seen. All times reported are in clock ticks. RETURN VALUE
times() returns the number of clock ticks that have elapsed since an arbitrary point in the past. The return value may overflow the possi- ble range of type clock_t. On error, (clock_t) -1 is returned, and errno is set appropriately. ERRORS
EFAULT tms points outside the process's address space. CONFORMING TO
SVr4, 4.3BSD, POSIX.1-2001. NOTES
The number of clock ticks per second can be obtained using: sysconf(_SC_CLK_TCK); In POSIX.1-1996 the symbol CLK_TCK (defined in <time.h>) is mentioned as obsolescent. It is obsolete now. In Linux kernel versions before 2.6.9, if the disposition of SIGCHLD is set to SIG_IGN then the times of terminated children are automati- cally included in the tms_cstime and tms_cutime fields, although POSIX.1-2001 says that this should only happen if the calling process wait(2)s on its children. This nonconformance is rectified in Linux 2.6.9 and later. On Linux, the buf argument can be specified as NULL, with the result that times() just returns a function result. However, POSIX does not specify this behavior, and most other UNIX implementations require a non-NULL value for buf. Note that clock(3) also returns a value of type clock_t, but this value is measured in units of CLOCKS_PER_SEC, not the clock ticks used by times(). On Linux, the "arbitrary point in the past" from which the return value of times() is measured has varied across kernel versions. On Linux 2.4 and earlier this point is the moment the system was booted. Since Linux 2.6, this point is (2^32/HZ) - 300 (i.e., about 429 million) seconds before system boot time. This variability across kernel versions (and across UNIX implementations), combined with the fact that the returned value may overflow the range of clock_t, means that a portable application would be wise to avoid using this value. To mea- sure changes in elapsed time, use clock_gettime(2) instead. Historical SVr1-3 returns long and the struct members are of type time_t although they store clock ticks, not seconds since the Epoch. V7 used long for the struct members, because it had no type time_t yet. BUGS
A limitation of the Linux system call conventions on some architectures (notably i386) means that on Linux 2.6 there is a small time window (41 seconds) soon after boot when times() can return -1, falsely indicating that an error occurred. The same problem can occur when the return value wraps passed the maximum value that can be stored in clock_t. SEE ALSO
time(1), getrusage(2), wait(2), clock(3), sysconf(3), time(7) COLOPHON
This page is part of release 3.44 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/. Linux 2012-10-22 TIMES(2)
All times are GMT -4. The time now is 06:16 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy