reg str concat


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers reg str concat
# 1  
Old 10-30-2008
reg file name creation

hi friends.
i want to create new file name depends upon user input value.......the format is "txt_VVVV.txt". is it possible?
#bin/ksh
typeset -i10 i = $1
case $i in
[1-9]*)
fil = "txt_000"$i".txt"
;;
[10-99]*)
fil = "txt_00" $i ".txt"
;;
*) echo "invalid filename"
exit
;;
esac
echo $fil
above i did script.. for displaying "txt_0001.txt" for input is 1 or "txt_0010.txt" for input is 10. but it is giving error, advice me to get input like above or suggest some other logic which is similar to "%o4d" in C

Last edited by ilayans; 10-30-2008 at 04:04 AM..
# 2  
Old 10-30-2008
Code:
read a
case ${a} in
   ?) echo 000${a};;
   ??) echo 00${a};;
   ???) echo 0${a};;
esac

# 3  
Old 10-30-2008
thanks zaxxon it's working..... Smilie how i have to check whether that file is available in that folder or not?

Last edited by ilayans; 10-30-2008 at 06:38 AM..
# 4  
Old 10-30-2008
Code:
[ -f "$fil" ] && echo "file exists" || echo "file does not exist"

# 5  
Old 10-31-2008
thnks wempy
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Concat name

Hi, I need help to combine the first 7 character of firstname if it is longer than 7and combine with the first character of lastname. ex: username lastname => usernaml user lastname => userl Thanks in advance. (10 Replies)
Discussion started by: xitrum
10 Replies

2. Shell Programming and Scripting

Bash shell script: Str(007) to int(7),increment it(8) & convert back to string(008)

Hi, I have the following requirement. There will be following text/line in a file (eg: search-build.txt) PRODUCT_VERSION="V:01.002.007.Build1234" I need to update the incremental build number (eg here 007) every time I give a build through script. I am able to search the string and get... (4 Replies)
Discussion started by: drwatson_droid
4 Replies

3. Shell Programming and Scripting

Concat

Hi All, My Input file contains: Input.txt Name|Marks ABC|10 GHI|10 JKL|20 MNO|20 PQR|30 Output.txt MARKS|NAME 10|ABC,GHI 20|JKL,MNO 30|PQR Thanks in advance (4 Replies)
Discussion started by: kmsekhar
4 Replies

4. Shell Programming and Scripting

concat 3 files

Hello Unix gurus, how to concat 3 files content side by side . i have 3 files more report1.txt select *from tab1 A JOIN tab1 B ON more report2.txt A.PK1=B.PK1 where more report3.txt A.AAA <> B.AAA or A.BBB <> B.BBB or A.CCC<> B.CCCC or .. .. .. A.ZZZ <> B.ZZZ; if i concatinate... (3 Replies)
Discussion started by: kanakaraju
3 Replies

5. UNIX for Dummies Questions & Answers

Req 1-liner for Awk, et al to find str position

Hi, I'm trying to find the position of a series of numbers within a large text file. The numbers are separated by spaces. This works fine: type Huge_File.txt | gawk "{print index($0,"255")}" But this does not: type Huge_File.txt | gawk "{print index($0,"188 028 239 160 016 190 137... (4 Replies)
Discussion started by: Lemming42
4 Replies

6. Shell Programming and Scripting

concat strings

Hello, I have a list of tablespaces in oracle and I want to concatenate 'drop tablespace' on the left of each line and 'INCLUDING CONTENTS AND DATAFILES' on the right of each line. Any idea how to do that? many thanks. PS: I tried to use excel and copy/paste it to vi. But I noticed many... (1 Reply)
Discussion started by: melanie_pfefer
1 Replies

7. Shell Programming and Scripting

concat fields

hi I have a file, I need to concatenate depening on the no of columns i need to concatenate. for example i need to concatenate field1,filed34,field2( no of columns is not always 3, it can be any number of fields) concat.ksh field1 field34 field2 how to achieve this, is there any argv ,argc... (10 Replies)
Discussion started by: markjason
10 Replies

8. Shell Programming and Scripting

how to get the pos() of 2 str matches in one loop in perl

Hello all i have this simple loop that gets me every time the match of "<#" in my string something like that : my $str ="gggg<#nnnnn#>kkkk<#ssss#>llllll"; while($str =~m/<#/g){ print pos($str); } but now i like to get another pos in the same loop iteration , i will like to get the... (1 Reply)
Discussion started by: umen
1 Replies

9. Shell Programming and Scripting

Concat

HI all, How to concat two strings in Shell scrpits suppose x=a y=b i want to display it as ab How to do it ? Thanks.. (1 Reply)
Discussion started by: dhananjaysk
1 Replies

10. Shell Programming and Scripting

how to search for a str and replace it..

in my file, i like to search for a string and if there is a match then i want to replace it with someother string(like in windows wordpad). i only know how to search for a pattern.... but i dont know how to replace it.. and 1). i think it is there in unix grep or some other commends... if... (6 Replies)
Discussion started by: sekar sundaram
6 Replies
Login or Register to Ask a Question