Sponsored Content
Top Forums Shell Programming and Scripting Read command restarts at beginning of file Post 302990288 by DJR on Tuesday 24th of January 2017 11:36:07 AM
Old 01-24-2017
Read command restarts at beginning of file

I am reading in a file in a Korn shell script. The file has one header row followed by possibly millions of data rows. I want to do one thing to the header row and write it out to a new output file, then something different to the data rows. My code looks like this:

Code:
read header < $infile 
    lineout=...$header...
echo $lineout >> $outfile
 
while read dataline
do
   lineout=....$dataline.....
   echo $lineout >> $outfile
done < $infile

But when I do this the while loop reads the first line in again - so I get the header line twice. The pointer goes back to the start of the file, or it closes and reopens, not sure what is going on. I know I could put the header logic in the while loop and just test for the first line and do that coding there. But I'd rather not have to do that test millions of times when I know I only need to process the first line differently. Why does the file reader not move to the next line? I assume the "done < $infile" part is forcing it to start at the beginning again. Anyway to make this work this way?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

File deletion when server restarts

Hi, In a shell script I am makin use of 3 files f1,f2 and f3.txt. When the Unix server is restarted I want to delete all these 3 files if they are existing. ( I suppose I will have to use this command rm /thefilepath/f* but dont know in which script to use.) Anyone knows what can be... (6 Replies)
Discussion started by: k_oops9
6 Replies

2. Shell Programming and Scripting

command to read file name and size

hi all, there is any command or anything we can use to read the file name and size. thanks (6 Replies)
Discussion started by: s_linux
6 Replies

3. Shell Programming and Scripting

Command filtering ONLY rows NOT beginning with '*'

I need a command which filters rows ONLY NOT beginning with '*' So far I have following NOT sufficient command, because it does not include ALL possible literals except of '*' grep ^ INPUT_FILE >>OUTPUT_FILE Is it possible to write something like grep NOT ^ INPUT_FILE... (3 Replies)
Discussion started by: ABE2202
3 Replies

4. UNIX for Dummies Questions & Answers

Command to delete numbers at beginning of txt file line

Hello. I have the following issue: my txt file has the following format: train/dr4/fklc0/sx175.txt 0 80282 Severe myopia contributed to Ron's inferiority complex. train/dr4/fklc0/sx355.txt 0 42906 Dolphins are intelligent marine mammals. train/dr4/fklc0/sa2.txt awk 'NR%2==0' test1.txt >... (4 Replies)
Discussion started by: li_bi
4 Replies

5. Shell Programming and Scripting

Command to remove numbers from beginning of txt file

Hello. I have the following issue: my txt file has the following format: train/dr4/fklc0/sx175.txt 0 80282 Severe myopia contributed to Ron's inferiority complex. train/dr4/fklc0/sx355.txt 0 42906 Dolphins are intelligent marine mammals. train/dr4/fklc0/sa2.txt With the... (1 Reply)
Discussion started by: li_bi
1 Replies

6. UNIX for Dummies Questions & Answers

Any tips/suggestions for a newbie beginning to read the Linux Kernel Source Code

Hi All, I recently downloaded the Linux kernel source code, added them all to a project in MS VC++ and plan to read through it so that I can improve the way I code, read/understand a large code database and hopefully contribute something to the development of the Linux OS. I have taken a... (3 Replies)
Discussion started by: clavian
3 Replies

7. Solaris

Unix restarts error in sar command

Hi Folks, I am again here with a peculier problem. Please see the code root@celdws01: # sar -u -f /var/adm/sa/sa21 SunOS celdws01 5.9 Generic_118558-34 sun4u 12/21/2011 10:10:09 %usr %sys %wio %idle 10:10:09 unix restarts Can anyone help me in... (9 Replies)
Discussion started by: vivek.goel.piet
9 Replies

8. Shell Programming and Scripting

Read from file and execute the read command

Hi, I am facing issues with the below: I have a lookup file say lookup.lkp.This lookup.lkp file contains strings delimited by comma(,). Now i want to read this command from file and execute it. So my code below is : Contents in the lookup.lkp file is : c_e,m,a,`cd $BOX | ls cef_*|tail... (7 Replies)
Discussion started by: vital_parsley
7 Replies

9. Shell Programming and Scripting

Read file and run a command

Hi I have jobs (some 1000) defined in a file and I want to read those jobs and run a a command. For example: jobs.txt abc efg I want to read the entire file and run the following command Delete -JOB "abc" Deleteing abc... Delete -JOB "efg" Delete efg... Can somebody help me... (4 Replies)
Discussion started by: karan8810
4 Replies

10. UNIX for Beginners Questions & Answers

Du command not able to read file.

hi when i am trying to check the file size using du command in shell script but getting a below error, although the file is present du: cannot access `LOGS_18-08-20.tar.gz': No such file or directory below is snippet of script cd /home dt=$(date --date="yesterday" +"%y-%m-%d") du ... (3 Replies)
Discussion started by: scriptor
3 Replies
DIME(1) 						      General Commands Manual							   DIME(1)

NAME
dxf2vrml - program to convert .dxf formatted 3-D datasets to .VRML format. SYNOPSIS
dxf2vrml [infile][-ooutfile][-emaxerr][-f][-l] DESCRIPTION
This manual page documents briefly the dxf2vrml command. (default infile is stdin, default outfile is stdout) This manual page was written for the Debian GNU/Linux distribution because the original program does not have a manual page. Instead, it has documentation in the GNU Info format; see below. dxf2vrml is a program that... OPTIONS
These programs follow the usual GNU command line syntax, with long options starting with two dashes (`-'). A summary of options is included below. For a complete description, see the Info files. infile default infile is stdin -o outfile, default outfile is stdout -e, Maximum error when tessellating curves -f, Respect the $FILLMODE header variable -vrml2, Write as vrml2. Default is vrml1 -l, Use layer color, ignore the color index -s, Set sub parameter -h, Show useage. SEE ALSO
files in: /usr/share/doc/libdime/, /usr/share/doc/libdime-dev/. The programs are documented fully by http://www.coin3d.org/lib/dime/, available via the Internet. AUTHOR
This manual page was written by A. Maitland Bottoms <bottoms@debian.org>, for the Debian GNU/Linux system (but may be used by others). January 11, 2002 DIME(1)
All times are GMT -4. The time now is 02:15 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy