The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to print lines till till a pattern is matched in loop anoopvraj Shell Programming and Scripting 3 10-30-2008 10:36 PM
how to read a file till it encounters a blank line adityam UNIX for Dummies Questions & Answers 1 11-26-2007 02:26 AM
how to read a file till it encounters a blank line adityam Shell Programming and Scripting 1 11-26-2007 02:15 AM
how to read a file till it encounters a blank line adityam Post Here to Contact Site Administrators and Moderators 0 11-26-2007 01:51 AM
need to read a file and keep waiting till it satisfies some condition senthilk615 Shell Programming and Scripting 1 03-22-2006 03:15 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-08-2008
vasuarjula vasuarjula is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 36
read file and print additional rows till current year

Hi all
i have a file like
2006,1,2
2007,2,3
2008,3,4

I will read this and my output should be like
2006,1,2
2007,1,2
2008,1,2
2007,2,3
2008,2,3
2008,3,4

Giving the explanation, we will read the first line of the file and if the year any other than current year, we will print as many rows as needed till we reach current year for ex
if the first line of the file is like : 2004,3,4
then the output records of that record will be : 2004,3,4
2005,3,4
2006,3,4
2007,3,4
2008,3,4
i hope we can do this by using while, but how can i print all the fields of a singe record to output.
  #2 (permalink)  
Old 12-09-2008
demwz demwz is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 128
current=2008
cat file | while read l ; do
a=(`echo $l | tr -s "," " "`)
for i in $(seq ${a[0]} $current) ; do
echo $i,${a[1]},${a[2]}
done
done
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:00 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0