cshell integer expression from "0000" to "1999"


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting cshell integer expression from "0000" to "1999"
# 1  
Old 11-03-2010
cshell integer expression from "0000" to "1999"

I have 2000 files named like "file-fr0000.log", "file-fr1999.log"...
I wanna generate the file names automatically in the following c shell script:

Code:
set fr = 0
while ($fr <= 1999)
    grep "ENERGY" file-fr$fr.log > data.dat
    @ fr = ( $fr + 1 )
end

The above will generate file names like "file-fr5.log" instead of the intended "file-fr0005.log".
How can I generate a series of number with fixed width like "0005", using zeros to fill those vacancies?

Appreciate your time!
Todd
# 2  
Old 11-03-2010
Code:
FILENAME=`printf "file-fr%04d.log" "$N"`

printf should be a builtin in most shells, not sure about csh.
# 3  
Old 11-03-2010
Thanks a lot, it works
Quote:
Originally Posted by Corona688
Code:
FILENAME=`printf "file-fr%04d.log" "$N"`

printf should be a builtin in most shells, not sure about csh.
# 4  
Old 11-04-2010
Code:
touch file-fr{0,1,2,3,4,5,6,7,8,9}{0,1,2,3,4,5,6,7,8,9}{0,1,2,3,4,5,6,7,8,9}{0,1,2,3,4,5,6,7,8,9}

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. AIX

Apache 2.4 directory cannot display "Last modified" "Size" "Description"

Hi 2 all, i have had AIX 7.2 :/# /usr/IBMAHS/bin/apachectl -v Server version: Apache/2.4.12 (Unix) Server built: May 25 2015 04:58:27 :/#:/# /usr/IBMAHS/bin/apachectl -M Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_worker_module (static) ... (3 Replies)
Discussion started by: penchev
3 Replies

2. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

3. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

4. UNIX for Dummies Questions & Answers

redirect for "[: : integer expression expected" error

Hi, I read in this forum that for "https://www.unix.com/shell-programming-scripting/156008-integer-expression-expected-regular-expression.html thanks! (7 Replies)
Discussion started by: Vijay81
7 Replies

5. Shell Programming and Scripting

why "aab" matchs "ab" when using reglar expression ?

Please see the following code, why "aab" matchs "ab" when using reglar expression ? $ ] && echo "ok" || echo "error"; ok $ ] && echo "ok" || echo "error"; error $ ] && echo "ok" || echo "error"; error $ ] && echo... (8 Replies)
Discussion started by: 915086731
8 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. Fedora

"integer expression expected" error with drive space monitoring script

Hi guys, I am still kinda new to Linux. Script template I found on the net and adapted for our environment: #!/bin/sh #set -x ADMIN="admin@mydomain.com" ALERT=10 df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read output; do #echo $output ... (2 Replies)
Discussion started by: wbdevilliers
2 Replies

8. Shell Programming and Scripting

error "integer expression expected" when selecting values

dear members, I am having some difficulties with an automation script that I am writing. We have equipments deployed over our network that generate status messages and I was trying an automated method to collect all information. I did a expect script that telnet all devices, logs, asks for... (4 Replies)
Discussion started by: jorlando
4 Replies

9. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies
Login or Register to Ask a Question