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 > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

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 03:20 PM
While Loop hemangjani Shell Programming and Scripting 2 11-02-2006 11:01 AM
for loop munnabhai1 Shell Programming and Scripting 3 04-06-2006 03:30 PM
how to get the similar function in while loop or for loop trynew Shell Programming and Scripting 3 06-17-2002 12:09 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-30-2007
bobo bobo is offline
Registered User
  
 

Join Date: Jan 2006
Posts: 148
Unhappy while loop help

data:

1234567890abcdefghij1234567890...

code:

cut -b1-10 data >> data1
cut -b11-20 data >> data1
cut -b21-30 data >> data1



my result:

1234567890
abcdefghij
1234567890
.........


How my codes should be if I would use "while syntax" coding?
  #2 (permalink)  
Old 01-31-2007
maheshwin maheshwin is offline
Registered User
  
 

Join Date: Dec 2006
Posts: 55
Quote:
Originally Posted by bobo
data:

1234567890abcdefghij1234567890...

code:

cut -b1-10 data >> data1
cut -b11-20 data >> data1
cut -b21-30 data >> data1



my result:

1234567890
abcdefghij
1234567890
.........


How my codes should be if I would use "while syntax" coding?


instead of while , u can use the awk which is very flexible enough to handle the task, since while suffers in searching a text
  #3 (permalink)  
Old 01-31-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Code:
awk ' { print substr($0,1,10) "\n" substr($0,11,10) "\n" substr($0,21,10) >> "data1" } ' data

Last edited by anbu23; 01-31-2007 at 02:47 AM..
  #4 (permalink)  
Old 01-31-2007
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,953
Code:
sed 's/\(.\{10\}\)\(.\{10\}\)\(.*\)/\1\
\2\
\3/' filename
  #5 (permalink)  
Old 01-31-2007
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,122
To loop through a string, 10 characters at a time:
Code:
$ cat looper
#! /usr/bin/ksh

string=aaaaaaaaaabbbbbbbbbccccccccccddddddddddeeeeeeeeeefffffffffffgggggggggg

typeset -L10 tenchr

while ((${#string})); do
        if ((${#string} > 10)); then
                tenchr=$string
                piece=$tenchr
                string=${string#$piece}
        else
                piece=$string
                string=""
        fi
        echo $piece $string
done
exit 0
$ ./looper
aaaaaaaaaa bbbbbbbbbccccccccccddddddddddeeeeeeeeeefffffffffffgggggggggg
bbbbbbbbbc cccccccccddddddddddeeeeeeeeeefffffffffffgggggggggg
cccccccccd dddddddddeeeeeeeeeefffffffffffgggggggggg
ddddddddde eeeeeeeeefffffffffffgggggggggg
eeeeeeeeef ffffffffffgggggggggg
ffffffffff gggggggggg
gggggggggg
$
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 11:32 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