New to Shell scripting: Can you check it?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting New to Shell scripting: Can you check it?
# 8  
Old 10-28-2008
Why want to copy?
Is there a reason why you cannot directly output to the file, to the correct location
e.g. >>$EXE_DIR/$htmlfile.txt
# 9  
Old 10-28-2008
take note of spaces in filenames when using the for loop with find. you can work around by changing IFS, do some quoting, or simply use the while read loop instead
Code:
find ..... | while read FILE
do
  # do something with $FILE
done

# 10  
Old 10-29-2008
Vbe
I cant directly output in a file as $htmlfile has a extension of .html ( for example it $htmlfile = a/b/c/d/123.html ) , I need to create a .txt file with the same name and on the same location, so I want a/b/c/d/123.txt

"So the output of a/b/c/d/123.html should go to a/b/c/d/123.txt"

if i use
>>$EXE_DIR/$htmlfile.txt

the name of the file will be a/b/c/d/123.html.txt
isn't it?

Thanks!
--------------
vbe wrote:
Why want to copy?
Is there a reason why you cannot directly output to the file, to the correct location
e.g. >>$EXE_DIR/$htmlfile.txt
1 Day Ago 12:07 AM
# 11  
Old 10-29-2008
Try this:

Code:
txtfile=`echo ${htmlfile%.*}.txt`
cp "$htmlfile" "$txtfile"


Last edited by Franklin52; 10-29-2008 at 06:43 PM.. Reason: forgot the backticks
# 12  
Old 10-29-2008
Posix shell (ksh, bash, etc) can work with strings, what you are trying to do can be done using ${%patterrn} notation

Here is a small example:

Code:
 
find /opt/K/SCO/COMMUNICATOR -name "*.htm" |while read f; do 
s=${f%\.*}".txt"; echo "Old: " ${f}; echo "New: " ${s};
done

I am escaping '.' with \. as the '.' itself is spec char for shell.

Reslult:

Old: /opt/K/SCO/COMMUNICATOR/4.7.0j/nethelp/picsfail.htm
New: /opt/K/SCO/COMMUNICATOR/4.7.0j/nethelp/picsfail.txt
Old: /opt/K/SCO/COMMUNICATOR/4.7.0j/nethelp/NSHIfrm.htm
New: /opt/K/SCO/COMMUNICATOR/4.7.0j/nethelp/NSHIfrm.txt
...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To check if the JAVA Program is successfully executed in sh shell scripting

Hi , I have written a shell script to call a java program say load_id.sh .This sh script indeed is executed implicitly in other sh script which calls 2 more sh scripts one by one. I need to check if the load_id.sh (which calls java program) is executed successfully only then continue with... (1 Reply)
Discussion started by: preema
1 Replies

2. Shell Programming and Scripting

How to check the datatypes of the columns are same through shell scripting?

Hi, We have a requirement like, to check the datatypes of columns against database. After loading the sample data in to one of the database, need to compare the datatypes of the columns are matching with the provided files. Is there a way that we can achieve through shell scripting. We... (7 Replies)
Discussion started by: Samah
7 Replies

3. AIX

Need help in scripting to check if rootvg is mirrored or not

Hi Can some one help me with a script which when executed will check and tell if all the LV's in rootvg are mirrored or not. Say for example in the below server we could see that everything is mirrored except dumplv2. So if I execute the script it should tell that all are mirrored except... (7 Replies)
Discussion started by: newtoaixos
7 Replies

4. Shell Programming and Scripting

C shell scripting, check if link exists on remote servers

Hi, I'm new to C Shell programming. I'm trying to check if a sym link exists on remote server if not send email. I'm not having much luck. Can anyone help? Here is what I have written but it doesn't work. It tells me that my variable was not defined. Here is part of the script, the second... (0 Replies)
Discussion started by: CDi
0 Replies

5. What is on Your Mind?

Shell Scripting vs Perl scripting

Gents, I have been working in a Solaris/Unix environment for about 9 months. I took some linux classses online before getting the job. But, I am not very good at scripting. I want to learn how to script. Do you think that I should start with Shell scripting or Perl? I wanted to continue with... (2 Replies)
Discussion started by: Pouchie1
2 Replies

6. Shell Programming and Scripting

Call Shell scripting from Perl Scripting.

Hi How to call a shell scripting through a Perl scripting? Actually I need some value from Shell scripting and passes in the Perl scripting. So how can i do this? (2 Replies)
Discussion started by: anupdas
2 Replies

7. UNIX for Dummies Questions & Answers

SQL Connection check though Scripting

Hi Guys, I wanted to check the sql connection through scripting if it is avilable then proceed else stop the process I was trying sqlplus -L username/passwd@sid if this is not sucess it gives non-zero. but if it is success it is going into the sqlplus prompt. So how could i get out... (2 Replies)
Discussion started by: Swapna173
2 Replies

8. Solaris

How to check the file existence using shell scripting in Solaris-10

Hi, I have a script which will check the fiel existence, the lines are as below if !(test -d ./data) then mkdir data fi In the first line error occurs as below generatelicense.sh: syntax error at line 2: `!' unexpected Where as this script works fine in linux OS. How to solve... (2 Replies)
Discussion started by: krevathi1912
2 Replies

9. UNIX for Dummies Questions & Answers

How to check process/cpu utilisation thru unix shell scripting

Dear Champs, Can anybody help me out to write a shell script , which will check whether the process is running , if running then divide the process into 2 so that next var it can take process parallel . Let ps -ef | grep a.sh => shows running note a.sh will take a process of next... (0 Replies)
Discussion started by: manas_ranjan
0 Replies

10. Shell Programming and Scripting

difference between AIX shell scripting and Unix shell scripting.

please give the difference between AIX shell scripting and Unix shell scripting. (2 Replies)
Discussion started by: haroonec
2 Replies
Login or Register to Ask a Question