Renaming Files Based on Contents


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Renaming Files Based on Contents
# 8  
Old 01-17-2010
Strange. I'd like to know what the values of F and N are before that. So insert this line before the problematic one
Code:
echo "F='$F' - N='$N'"

# 9  
Old 01-17-2010
F='99_REPORT_2222' - N='CARSBLU'
./testscript[8]: NEW=${F:0:9}.${N}${F:9}: bad substitution
# 10  
Old 01-17-2010
That's right, I don't have the same problem what we can do ist to find what expression gives you that error so comment that line
Code:
# NEW=${F:0:9}.${N}${F:9}

and put this under to see what happens :
Code:
echo ${F:0:9}
echo ${F:9}

# 11  
Old 01-17-2010
Quote:
Originally Posted by DerangedNick
F='99_REPORT_2222' - N='CARSBLU'
./testscript[8]: NEW=${F:0:9}.${N}${F:9}: bad substitution
what shell you are using, is it csh?...in frans posts it seems either bash or ksh
# 12  
Old 01-18-2010
I am using ksh according to the command ps -p $$. This is an AIX 5.3 TL 11 box not sure if that helps with anything
# 13  
Old 01-18-2010
Code:
NEW=${F:0:9}.${N}${F:9}

Try wrapping this in quotes like:

Code:
NEW="${F:0:9}.${N}${F:9}"

# 14  
Old 01-18-2010
root@testbox:/testscript # ./testscript
F='99_REPORT_2222' - N='CARSBLU'
./testscript[8]: NEW="${F:0:9}.${N}${F:9}": bad substitution

I put it on quotes and received that, however if anyone does mind can they explan what exactly the 0:9 is doing? I might be able to play with it a bit more if I understood that part of it.

Thanks

---------- Post updated at 11:29 PM ---------- Previous update was at 11:24 PM ----------

Quote:
Originally Posted by frans
That's right, I don't have the same problem what we can do ist to find what expression gives you that error so comment that line
Code:
# NEW=${F:0:9}.${N}${F:9}

and put this under to see what happens :
Code:
echo ${F:0:9}
echo ${F:9}

I just saw your post, I did the
echo ${F:0:9} and the
echo ${F:9} one at a time but they are both giving the error bad substitution.

It just seems to end the script once it hits that error.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to remove a line based on contents of the first column?

Good day all. Using basic UNIX/Linux tools, how would you delete a line based on a character found in column 1? For example, if the CITY name contains an 'a' or 'A', delete the line: New York City; New York Los Angeles; California Chicago; Illinois Houston; Texas Philadelphia;... (3 Replies)
Discussion started by: BRH
3 Replies

2. Shell Programming and Scripting

Computing difference based on line contents

I have the following awk script set up to copy the contents of a line that contains 0008 in each line that contains values of 1895 through 2012. awk -v OFS=" " '{val=0+substr($1,length($1)-3,4);if(val==0008){print;$1=x;y=$0}else{if(val>=1895&&val<=2012){print $1 y}else{print}}}' Output... (7 Replies)
Discussion started by: ncwxpanther
7 Replies

3. Shell Programming and Scripting

File comparison based on contents

Hi I have 2 files 1.del ---- 1,2,3,4,5 1,2,3,4,4 1,1,1,1,2 2.del ---- 1,2,3,4,5 1, 1,2,3,4,4 1,1,1,1,2 I need to compare the above two files in unix, as in the output should only tell the difference in contents as I should get only the line 1 ( from 2.del) , rest all lines are... (4 Replies)
Discussion started by: Ethen561
4 Replies

4. Shell Programming and Scripting

Concatenating many files based on a specific column contents

Dear all, I have many files(.csv) in a directory. I want to concatenate the files which have similar entries in a particular column and save into a new file like result_datetime.csv etc. One example file is like below. Sno,Step,Data1,Data2,Data3 etc. 1,0,2,3,4 2,1,3,4,5 3,2,0,1,1 ... (4 Replies)
Discussion started by: ks_reddy
4 Replies

5. Shell Programming and Scripting

Splitting large file and renaming based on field

I am trying to update an older program on a small cluster. It uses individual files to send jobs to each node. However the newer database comes as one large file, containing over 10,000 records. I therefore need to split this file. It looks like this: HMMER3/b NAME 1-cysPrx_C ACC ... (2 Replies)
Discussion started by: fozrun
2 Replies

6. UNIX for Dummies Questions & Answers

count values based on contents of another file

Hello, I have two files as shown below: test1 678 679 689 690 710 test2 1 678 654 800 676 791 689 900 I want to get a count of lines from test2 whose columns bound the values in test1 I tried running the code below; however am getting wrong results. (3 Replies)
Discussion started by: Gussifinknottle
3 Replies

7. Shell Programming and Scripting

Renaming files based on data in a spreadsheet

I have a spreadsheet in a folder that looks like this: Sector1...Sector2...Sector3...Sector4...Sector5...Sector6...Sector7 SomeID....Title.......SomeID...SomeID....SomeID...SomeID....SomeID OtherID...MyTitle....SomeID...SomeID....SomeID...SomeID....SomeID... (7 Replies)
Discussion started by: Xterra
7 Replies

8. Shell Programming and Scripting

Manipulating word based off of contents

Hello everyone, my first post here, please feel free to inform me if my question can be better formatted so my future posts may be more clear. I have a large text file which I need parsed in one specific way, I have done the rest of the processing, I am simply lacking the last aspect of such. ... (8 Replies)
Discussion started by: ryanfx
8 Replies

9. Shell Programming and Scripting

Merging files based on the contents

Hi, I have a file f1 having the contents as below select (<condn>) from dual I have another file f2 having the contents as below 1, 2, 3 I want to replace <condn> in f1 with the contents of f2 I tried using sed like this sed "s:<condn>:`cat f2`:g" f1 The above command resulted in sed:... (3 Replies)
Discussion started by: mr_manii
3 Replies

10. Shell Programming and Scripting

Remove lines based on contents of another file

So, this issue is driving me nuts! I was hoping to get a lending hand here... I have 2 files: file1.txt contains: this is example1 this is example2 this is example3 this is example4 this is example5 file2.txt contains: example3 example5 Basically, I need a script or command to... (4 Replies)
Discussion started by: bashshadow1979
4 Replies
Login or Register to Ask a Question