Sponsored Content
Full Discussion: Assigning file to a variable
Top Forums Shell Programming and Scripting Assigning file to a variable Post 302817079 by balajesuri on Wednesday 5th of June 2013 06:32:03 AM
Old 06-05-2013
Quote:
Originally Posted by brunlea
I have a list of files in a directory. Each file has a .txt and a .log extension i.e. file.txt & file.log, file1.txt & file1.log etc. The file with the .log extension may not always exist alongside the file with the .txt extension.
I need to copy the .txt file if there is a corresponding .log file with it. If there is no .log file, then do not do the copy. Once the file has been copied i need to delete it.
Code:
for txtfile in /home/dir/*txt
do
    filename=${txtfile%.*}
    filename=${filename##*/}
    
    if [ -e "${filename}.log" ]
    then
        cp $txtfile /home/newdir/
        rm -f $txtfile
    fi
done

This User Gave Thanks to balajesuri For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Reading file and assigning that to Variable

I am missing something here, I have a file which contains only one line and that is either a number or character string. I am trying to read the file and assign that value to a variable and here it seems I am missing something and not getting the expected results... Here is the code : #!/bin/ksh... (2 Replies)
Discussion started by: Vaddadi
2 Replies

2. UNIX for Dummies Questions & Answers

Assigning value in a text file to a variable

Hi, I need to place a number located in a text file in a variable so I can perform if/then comparison. How would I go about doing this? Using A=awk '{print $2}' maintenance_date.tmp does not seem to work. Thanks (1 Reply)
Discussion started by: mojoman
1 Replies

3. UNIX for Dummies Questions & Answers

Searching a text file and assigning it to a variable

Hi Gurus, I am new to unix.I have a requirement as below I have text file like a.txt which contains a.txt hi hello process update status Ok to Proceed no issues good data arrangement My requirement here is i need to read the file and check for the words "OK to Proceed" and if... (2 Replies)
Discussion started by: pssandeep
2 Replies

4. Shell Programming and Scripting

Reading data from file and assigning to variable

I was trying to store the number of lines in a file and store it in a file.after that i want to store the information in a file to a variable which is further used in the if loop to check certain condition. #!/bin/bash cat <file> | wc -l > count.txt x="$count.txt"; i=10; if ; then cat... (10 Replies)
Discussion started by: sudhakaryadav
10 Replies

5. Shell Programming and Scripting

Removing a character from a variable and assigning it to another variable?

Hi folks. I have this variable called FirstIN that contains something like this: 001,002,003,004... I am trying to assign the content of this variable into ModifiedIN but with the following format : 001 002 003 004...(changing the commas for spaces) I thought about using sed but i am not... (17 Replies)
Discussion started by: Stephan
17 Replies

6. Shell Programming and Scripting

how to Read a file and assigning each line to a variable?

Friends, I have a file output.txt with values as below: 092307135717 061910135717 I want to know how to read this file and then assign each value to a variable. say like var1=092307135717 var2=061910135717 So that I can use this VAR1 and Var2 in the shell script for further processing.... (3 Replies)
Discussion started by: shyamaladevi
3 Replies

7. Shell Programming and Scripting

Assigning a value as a variable from a text file

I have a txt file output.txt Freq = 1900 L = 159I want to assign the values to a variable so that i can further use it in some other script. like F=1900 Len=159 etc i tried doing something with awk but dosent work F=$(awk 'BEGIN {}/Freq/ {split ($2,a);depth=a};printf "%d\t,... (2 Replies)
Discussion started by: shashi792
2 Replies

8. Shell Programming and Scripting

problem in assigning value to variable have value fo other variable

my script is some thing like this i11="{1,2,3,4,5,6,7,8,9,10,11,}" echo "enter value" read value ..............suppose i11 x="$value" echo "$($value)" .............the echo should be {1,2,3,4,5,6,7,8,9,10,11,} but its showing "i11" only. plz help me out to get desired... (10 Replies)
Discussion started by: sagar_1986
10 Replies

9. Shell Programming and Scripting

assigning variable in txt file

Hi all, One of my txt file has common format like . And I need to manually assign variable to "/a/b/c/file1/txt" , which has common text before "Calculated summary file:". I wonder if I can use some command to do that for me, that it read the file and check for that comonn text and assign... (2 Replies)
Discussion started by: emily
2 Replies

10. Shell Programming and Scripting

Assigning a variable

I have a date column as 06302015 but I need to have variable which extracts 063015. Am trying something like below but it is not assigning Please let me know if am missing something. Thanks in advance. ################################ #!/usr/bin/ksh DT=06302015 ... (7 Replies)
Discussion started by: weknowd
7 Replies
Log::Handler::Config(3pm)				User Contributed Perl Documentation				 Log::Handler::Config(3pm)

NAME
Log::Handler::Config - The main config loader. SYNOPSIS
use Log::Handler; my $log = Log::Handler->new(); # Config::General $log->config(config => 'file.conf'); # Config::Properties $log->config(config => 'file.props'); # YAML $log->config(config => 'file.yaml'); Or use Log::Handler; my $log = Log::Handler->new(); $log->config( config => 'file.conf' plugin => 'YAML', ); DESCRIPTION
This module makes it possible to load the configuration from a file. The configuration type is determined by the file extension. It's also possible to mix file extensions with another configuration types. PLUGINS
Plugin name File extensions ------------------------------------------ Config::General cfg, conf Config::Properties props, jcfg, jconf YAML yml, yaml If the extension is not defined then "Config::General" is used by default. METHODS
config() With this method it's possible to load the configuration for your outputs. The following options are valid: config With this option you can pass a file name or the configuration as a hash reference. $log->config(config => 'file.conf'); # or $log->config(config => \%config); plugin With this option it's possible to say which plugin you want to use. Maybe you want to use the file extension "conf" with "YAML", which is reserved for the plugin "Config::General". Examples: # this would use Config::General $log->config( config => 'file.conf' ); # this would force .conf with YAML $log->config( config => 'file.conf', plugin => 'YAML' ); section If you want to write the configuration into a global configuration file then you can create a own section for the logger: <logger> <file> filename = file.log minlevel = emerg maxlevel = warning </file> <screen> minlevel = emerg maxlevel = debug </screen> </logger> <another_script_config> foo = bar bar = baz baz = foo </another_script_config> Now your configuration is placed in the "logger" section. You can load this section with $log->config( config => 'file.conf', section => 'logger', ); # or if you load the configuration yourself to %config $log->config( config => \%config, section => 'logger', ); # or just $log->config( config => $config{logger} ); PLUGINS
Config::General - inspired by the well known apache config format Config::Properties - Java-style property files YAML - optimized for human readability EXAMPLES
Config structures A very simple configuration looks like: $log->config(config => { file => { alias => 'file1', filename => 'file1.log', maxlevel => 'info', minlevel => 'warn', }, screen => { alias => 'screen1', maxlevel => 'debug', minlevel => 'emerg', } }); Now, if you want to add another file-output then you can pass the outputs with a array reference: $log->config(config => { file => [ { alias => 'file1, filename => 'file1.log', maxlevel => 'info', minlevel => 'warn', }, { alias => 'file2', filename => 'file2.log', maxlevel => 'error', minlevel => 'emergency', } ], screen => { alias => 'screen1', maxlevel => 'debug', minlevel => 'emerg', }, }); It's also possible to pass the outputs as a hash reference. The hash keys "file1" and "file2" will be used as aliases. $log->config(config => { file => { file1 => { filename => 'file1.log', maxlevel => 'info', minlevel => 'warn', }, file2 => { filename => 'file2.log', maxlevel => 'error', minlevel => 'emergency', } }, screen => { alias => 'screen1', maxlevel => 'debug', minlevel => 'emerg', }, }); If you pass the configuration with the alias as a hash key then it's also possible to pass a section called "default". The options from this section will be used as defaults. $log->config(config => { file => { default => { # defaults for all file-outputs mode => 'append', }, file1 => { filename => 'file1.log', maxlevel => 'info', minlevel => 'warn', }, file2 => { filename => 'file2.log', maxlevel => 'error', minlevel => 'emergency', } }, screen => { alias => 'screen1', maxlevel => 'debug', minlevel => 'emerg', }, }); Examples for the config plugins Config::General <file> alias = file1 fileopen = 1 reopen = 1 permissions = 0640 maxlevel = info minlevel = warn mode = append timeformat = %b %d %H:%M:%S debug_mode = 2 filename = example.log message_layout = '%T %H[%P] [%L] %S: %m' </file> Or <file> <file1> fileopen = 1 reopen = 1 permissions = 0640 maxlevel = info minlevel = warn mode = append timeformat = %b %d %H:%M:%S debug_mode = 2 filename = example.log message_layout = '%T %H[%P] [%L] %S: %m' </file1> </file> YAML --- file: alias: file1 debug_mode: 2 filename: example.log fileopen: 1 maxlevel: info minlevel: warn mode: append permissions: 0640 message_layout: '%T %H[%P] [%L] %S: %m' reopen: 1 timeformat: '%b %d %H:%M:%S' Or --- file: file1: debug_mode: 2 filename: example.log fileopen: 1 maxlevel: info minlevel: warn mode: append permissions: 0640 message_layout: '%T %H[%P] [%L] %S: %m' reopen: 1 timeformat: '%b %d %H:%M:%S' Config::Properties file.alias = file1 file.reopen = 1 file.fileopen = 1 file.maxlevel = info file.minlevel = warn file.permissions = 0640 file.mode = append file.timeformat = %b %d %H:%M:%S file.debug_mode = 2 file.filename = example.log file.message_layout = '%T %H[%P] [%L] %S: %m' Or file.file1.alias = file1 file.file1.reopen = 1 file.file1.fileopen = 1 file.file1.maxlevel = info file.file1.minlevel = warn file.file1.permissions = 0640 file.file1.mode = append file.file1.timeformat = %b %d %H:%M:%S file.file1.debug_mode = 2 file.file1.filename = example.log file.file1.message_layout = '%T %H[%P] [%L] %S: %m' PREREQUISITES
Carp Params::Validate EXPORTS
No exports. REPORT BUGS
Please report all bugs to <jschulz.cpan(at)bloonix.de>. If you send me a mail then add Log::Handler into the subject. AUTHOR
Jonny Schulz <jschulz.cpan(at)bloonix.de>. COPYRIGHT
Copyright (C) 2007-2009 by Jonny Schulz. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.14.2 2012-11-21 Log::Handler::Config(3pm)
All times are GMT -4. The time now is 06:21 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy