Variable assignment for file names.


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Variable assignment for file names.
# 1  
Old 05-29-2003
Error Variable assignment for file names.

I am trying to process error files in selected directories. I can count the files that are there and export the contents to a file for either emailing or printing. The next step is to move the files to a processed directory with the name changed to .fixed as the last extension.
Code:
for file in $LOGFILES
	do
	if [ -d $file ]; then
	               echo "$file, is not a file, and will not be processed."
	else
		echo "Move $file to /intended destination.[Y/N] \c"
		read move_file
		if [ "$move_file" = "y" ] || [ "$move_file" = "Y" ]; then
			file2=`file'.fixed'`
			mv -i $PWDIR/$file /intended destination/$file2
			echo "Error file, $file has been renamed to $file2."
			echo "and moved sucessfully to $PWDIR."
				echo ""
			elif [ "$move_file" = "n" ] || [ "$move_file" = "N" ]; then
			echo "Moving of $file, cancelled."
			echo ""
		fi
	fi
	done
	echo "All files have been processed."

ANy help will be apprciated.

Smilie

added code tags for readability --oombera

Last edited by oombera; 02-17-2004 at 03:53 PM..
# 2  
Old 05-29-2003
Try
file2=${file}.fixed
# 3  
Old 05-29-2003
Perfect!!!

Boy some times the obvious is to easy.

Thanks
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Extract file names from file and set variable to 'highest' one

HI Folks - I have a requirement where I need to scan a text file for a list of files. The file, we'll called it, files.txt looks like such: inbox/EBS/Client_GL_Detail_PBCS_112517_SEP2017.txt inbox/EBS/Client_GL_Detail_PBCS_112617_NOV2017.txt ... (9 Replies)
Discussion started by: SIMMS7400
9 Replies

2. Shell Programming and Scripting

Find matching file in bash with variable file names but consisent prefixs

As part of a bash the below line strips off a numerical prefix from directory 1 to search for in directory 2. for file in /home/cmccabe/Desktop/comparison/missing/*.txt do file1=${file##*/} # Strip off directory getprefix=${file1%%_*.txt} ... (5 Replies)
Discussion started by: cmccabe
5 Replies

3. Shell Programming and Scripting

[awk] printing value of a variable assignment from a file

Heyas Me try to print only the value of a (specific) variable assignment from a file. What i get (1): :) tui $ bin/tui-conf-get ~/.tui_rc TUI_THEME dot-blue "" "$TUI_DIR_INSTALL_ROOT/usr" "$TUI_DIR_INSTALL_ROOT/etc/tui" "$TUI_PREFIX/share/doc/tui" "$TUI_PREFIX/share/tui"... (2 Replies)
Discussion started by: sea
2 Replies

4. Programming

FORTRAN: Loop over variable file names

Hi guys I'm a beginner in fortran. So excuse me for my naivety, let me briefly describe what I was trying to do. I have let's say 2 files named reac-1 and reac-2. After opening these files I've to do some calculations, close these files and open the same files again in a loop. So my faulty code... (6 Replies)
Discussion started by: saleheen
6 Replies

5. Shell Programming and Scripting

how to assign file names to array variable?

I wish to assign file names with particular extention to array variables. For example if there are 5 files with .dat extention in /home/sam then i have to assign these 5 files to an array. plz help me how to accomplish this. Thanks in advance. (4 Replies)
Discussion started by: siteregsam
4 Replies

6. Shell Programming and Scripting

set a variable to be a list of file names

Hi all, I am trying to get a list of all the .tif images in my folder and set a variable that holds all the file names using C shell. What is the best way to do it? any help would be greatly appreciated. Yang (4 Replies)
Discussion started by: lionheartyoung
4 Replies

7. Shell Programming and Scripting

Replace variable names in text file with its value

Hi I have a text file (mytext.txt), the content of which is as following: My name is <@MY_NAME@> and my age is <@MY_AGE@> . Now i have another property file (myprops) which is as following: MY_NAME=abcdefgh MY_AGE=000000 I was wondering, how can i replace the tags of mytext.txt, with its... (1 Reply)
Discussion started by: vigithvg
1 Replies

8. Shell Programming and Scripting

File Names in a Variable in a loop

Hi All , I am having confusion in a shell script. Please guide me. I need to get multiple files (number of files vary time to time, file names are separated by '|') using FTP get from the remote server. Actually, i call the FTP function in a loop. At the last step, i need to move all the get... (3 Replies)
Discussion started by: spkandy
3 Replies

9. Shell Programming and Scripting

awk variable assignment in a file

Hi All, I have a little awk script which uses a variable (x): awk -v x=0 'NF != 6 { ++x } END { print "This batch had " x " errors out of ", NR" records"}' But when I've tried to put the command in a file I can't seem to declare the variable. I've managed to simplify the code so that I... (4 Replies)
Discussion started by: pondlife
4 Replies
Login or Register to Ask a Question