LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-14-2001, 12:34 PM   #1
rand07
LQ Newbie
 
Registered: Feb 2001
Posts: 12

Rep: Reputation: 0
Talking


I need to do a circular shift with an input file with any number of words.

Input:
This is a file

Output:
This is a file
file This is a
a file This is
is a file This

Can anyone help? Thanks.
 
Old 04-15-2001, 11:29 AM   #2
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
Is this what you are looking for? It loads up an array from a file and prints the indices with the last index being the first index the next time through the master loop. There may be a simpler way.

Code:
#!/bin/sh

INFILE="readfile"
declare -a WORDARRAY
WORDARRAY=(`cat $INFILE`)
WORDCOUNT=`echo ${WORDARRAY[@]} | wc -w`
NUMCYCLES=$WORDCOUNT
COUNT=0
CURRENT=0
while [ $COUNT -lt $NUMCYCLES ]; do
   INDEX=0
   while [ $INDEX -lt $WORDCOUNT ]; do
      INDEX=`expr $INDEX + 1`
      printf "${WORDARRAY[CURRENT]} "
      if [ $INDEX -lt $WORDCOUNT ]; then
         CURRENT=`expr $CURRENT + 1`
      fi
      if [ $CURRENT -eq $WORDCOUNT ]; then
         CURRENT=0
      fi
   done
   printf "\n"
   COUNT=`expr $COUNT + 1`
done
[Edited by crabboy on 04-15-2001 at 12:33 PM]
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash script Linh Programming 4 04-21-2004 05:19 PM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 AM
bash script - incrementing a filename in a script tslinux Programming 10 08-05-2003 11:58 PM
bash script brian0918 Programming 7 06-12-2003 06:06 PM
bash script prob: how can i tell the script that a 'dd' has finished? Frustin Linux - General 2 04-02-2003 05:34 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration