![]() |
|
#1
|
||||
|
||||
Read a file line by line, shell scriptI've got a file that is of variable length, it will always have a minimum of two lines but no maximum. The first line contains either ON or OFF. The rest of the lines are numbered and contain the Month Day Time. The file looks like this:
Code:
I'm trying to write some code that will remove the second line of the file and renumber the others. Here is what I had: Code:
This works fine as long as the date isn't the smaller then the number of entries in the file. When it is, it causes issues. I was thinking of using the cut command with a "/n" delineator but I can't get that to work. Does anyone have any suggestions as to how to do this? __________________
"To argue with a person who has renounced the use of reason is like administering medicine to the dead." -Thomas Paine www.sullivan-county.com/deism.htm |
||||
|
#2
|
|||
|
|||
Re: Read a file line by line, shell scriptQuote:
Are you always going to write "ON" as the first line of the output file, as your code seems to indicate? Since you don't indicate any kind of error checking, couldn't you just use something like the following: Code:
(This is just to show how simple the awk stuff can be. Whatever you did to get the input file and output file names is still up to you.) File test.txt: Code:
Code:
On the other hand, If, as you described it, you want to reproduce the first line exactly as it appeared, and then skip the second line and renumber the rest, then the awk part could look like: Code:
File modified.txt after this one: Code:
If this doesn't meet your needs, then maybe you could give a complete program specification. Regards, Dave |
|
#3
|
||||
|
||||
Re: Read a file line by line, shell scriptThanks this is what I need. I think I'm still stuck thinking approaching shell programming as if it were C++. I've never seen awk used like that and it never occured to me to try that. Anyway to answer your questions, Yes I will always put ON as the first line, if it's OFF the script won't run anyway. All the error checking is elsewhere. This is but one function of many. Thanks for your help dave.
__________________
"To argue with a person who has renounced the use of reason is like administering medicine to the dead." -Thomas Paine www.sullivan-county.com/deism.htm |
Recent GIDBlog
Install Adobe Flash - Without Administrator Rights by LocalTech
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Airport Log program using 3D linked List : problem reading from file | batrsau | C Programming Language | 11 | 29-Feb-2008 07:44 |
| Help! Problems encountered while burning CD's | RayDarkness | Computer Software Forum - Windows | 1 | 18-Nov-2006 04:54 |
| CD burner wont burn!! | robertli55 | Computer Hardware Forum | 1 | 18-Jun-2004 10:53 |
| Yet another CD burner problem: Lite-On LSC-24082K | Erwin | Computer Hardware Forum | 1 | 22-May-2004 11:28 |
| Can't view pages from another machine on the Intranet | aevans | Apache Web Server Forum | 9 | 14-May-2004 02:26 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The