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
while loop inside while loop panknil Shell Programming and Scripting 0 01-07-2008 12:49 PM
For loop xramm HP-UX 3 10-10-2007 02:20 PM
For Loop help princssashes UNIX for Dummies Questions & Answers 2 11-09-2006 05:37 AM
While Loop hemangjani Shell Programming and Scripting 2 11-02-2006 11:01 AM
how to get the similar function in while loop or for loop trynew Shell Programming and Scripting 3 06-17-2002 11:09 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 04-06-2006
munnabhai1 munnabhai1 is offline
Registered User
  
 

Join Date: Apr 2006
Posts: 2
for loop

i have a file like below

1
2
3
4
5
6
7


what if i want to loop thru every 3rd line. the output will be
1
5

1) how can i do this in for loop.
  #2 (permalink)  
Old 04-06-2006
d_swapneel14 d_swapneel14 is offline
Registered User
  
 

Join Date: Mar 2006
Location: Mumbai,India
Posts: 57
all the best

hi

i m not sure. i will post actual code tommarow.

First - read a file into vaiable like
read var < cat filename [ test]

Next start a for loop by using number of lines in a file [ test]

for icnt -eq lcount

rof

u can get number of lines lcount as -- wc filename

then use a flg -- a print a line

all the best

Regards,
Swapneel


i m just giving you logic. as i think this is a Homework. and u can not post home work on this foroum. so try your best.

all the best
  #3 (permalink)  
Old 04-06-2006
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
Please read our rules which state:

(4) Do not 'bump up' questions if they are not answered promptly. No duplicate or cross-posting and do not report a post where your goal is to get an answer more quickly.

and

(6) Do not post classroom or homework problems.


If you want lines 1,5,9,13... which is not exactly every third line, you can use sed:

yes|nl|sed 'p;N;N;N;d'


It's not a for loop, but it's a good solution if this isn't homework.
  #4 (permalink)  
Old 04-06-2006
bmwm3guy bmwm3guy is offline
Registered User
  
 

Join Date: Apr 2006
Posts: 2
Talking

hi. sed command works perfect. here are some links which would be really helpful for sed command can't give you the answer.
http://www.computerhope.com/unix/used.htm
Sponsored Links
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:26 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