The UNIX and Linux Forums  


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
Formatted Output dhanamurthy Shell Programming and Scripting 6 05-13-2008 03:30 AM
Formatted output - awk dhanamurthy Shell Programming and Scripting 3 05-12-2008 12:25 AM
formatted output with commas joeyg Shell Programming and Scripting 4 03-04-2008 03:54 PM
Formatted output in KSH psynaps3 Shell Programming and Scripting 1 07-05-2006 09:03 AM
How to concatenate two strings or several strings into one string in B-shell? fontana Shell Programming and Scripting 2 08-26-2005 12:58 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-05-2009
sera1711 sera1711 is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 1
csh formatted strings

Hi,

currently I'm trying to write a csh script that should do the following:

set i = 1
while ($i < 100) {
cp AAA BBB
set i = $i +1
}

where AAA is a string like this file.11.txt, file.21.txt, ...
and BBB is a string like this file_0001, file_0002, ...

Is it possible to generate the string AAA and BBB automatically from the variable i?

Every hint is appreciated!
Kind regards,
Sebastian.
  #2 (permalink)  
Old 01-06-2009
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,365
Quote:
Originally Posted by sera1711 View Post
Hi,

currently I'm trying to write a csh script that should do the following:

set i = 1
while ($i < 100) {
cp AAA BBB
set i = $i +1
}

where AAA is a string like this file.11.txt, file.21.txt, ...
and BBB is a string like this file_0001, file_0002, ...

Is it possible to generate the string AAA and BBB automatically from the variable i?

It's simple in a Bourne-type shell:


Code:
i=1
while [ $i -lt 100 ]
do
  case $i in
     ?) nf=000$i ;;
    ??) nf=00$i ;;
   ???) nf=0$i ;;
  esac
  cp "file.$1.txt" "file_$nf"
done

You'll find it easier to write scripts in a standard shell and much easier to get help.
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 03:59 AM.


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