Sponsored Content
Full Discussion: Assigning file to a variable
Top Forums Shell Programming and Scripting Assigning file to a variable Post 302817137 by brunlea on Wednesday 5th of June 2013 10:17:00 AM
Old 06-05-2013
That's brilliant. Thanks

---------- Post updated at 08:41 AM ---------- Previous update was at 08:00 AM ----------

I am trying to do the copy all in one go rather than one file at a time, by assigning the file name to an array. Is this possible?

Code:
i=0
for x in /home/dir/*.log
do
TXTFile=$(basename $x ".log")
filename=$TXTFile.[^log]
[ -f $filename ] && filearr[$i]=$filename
i=$(($i+1))
done
cp ${filearr[@]} /home/dir/folder/.

With the above code i am not able to get the correct filename into $filename. It always appears as file1.[^log], file2.[^log] etc.

Any way i can get it into an array?

---------- Post updated at 09:17 AM ---------- Previous update was at 08:41 AM ----------

ok, i think i've got it:

Code:
i=0
for x in /home/dir/*.log
do
TXTFile=$(basename $x ".log")
filename=`find /home/dir/ -name ""$TXTFile".*"|grep -v .flg`
[ -f $filename ] && filearr[$i]=$filename
i=$(($i+1))
done
cp ${filearr[@]} /home/dir/folder/.

 

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
CVS2HTML(1)						       Debian user's manual						       CVS2HTML(1)

NAME
cvs2html - render a CVS commit log in HTML SYNOPSIS
cvs2html [-a[-b][-k]] [-n numdif] [-l/-L home] [-e] [-f] [-d MMM DD [YYYY]] [-D DD] [-i image]] [-h] [-v] [-w framewidth] [-s percentage] [-N maxchrono] [-rrev1:rev2] [-c|-C cfilename] -O | -o htmlname [-p cvspath] [-v verbosity] DESCRIPTION
The cvs2html script fetches the commit log for a CVS module and renders it in HTML. -a Generate additional fields and files containing differences between versions in an xdiff-like side by side manner. -b Use spaces as breakpoints to wrap the text, if -a is specified. This is used to stop the two columns from exceeding the total width. -c | -C filename Save a chronologically sorted list of all log entries in html format in filename. Use -C to reverse-sort the file. -d MMM DD [YYYY] Omit all log messages prior to the given date. The first three letters of the month should be used (eg Jun 5). The year is optional. -D DD Omit all log messages older than DD days. -e Print log messages in courier (non-proportional) font. -f Generate individual log files for each file when using -o. -h Show help -i image Make image the background image. -k Ignore changes in lines caused by CVS-keyword substitutions when -a is specified. -l home Make links relative to home. -L home Make links relative to home, but substitute file extensions with .html. -n numdiff Output only the latest numdiff diffs in the log. Older commits will only have the log data displayed. -N maxchrono Show only the latest maxchrono file changes in the chronological list of changes. -o output If output is a directory, all html files produced are stored there, using the name of the repository as the base filename. Other- wise, output is used as the base name. Generate frames for easier browsing. -O output If output is a directory, all html files produced are stored there, using the name of the repository as the base filename. Other- wise, output is used as the base name. -P cvspath Set the cvs path to cvspath. -rrev1:rev2 Show only the log messages between rev1, and rev2. If a file isn't tagged, then the whole revision story of the file is shown. -s percentage Make the width of the left frame, percentage of the window. -v Insert CVSROOT information in the index. -V verbosity Set the verbosity. The higher verbosity is, the more output is printed out. -w framewidth Make the width of the left frame, framewidth pixels. EXAMPLE
cvs2html -l http://cvs.sslug.dk/linuxbog -f -p \ -o cvs2html/index.html -v -a -b -n 6 -C chrono.html Will create a directory called cvs2html directory. This directory will contain a log data file, for every file in the repository. The last 6 commits to every file will have a diff available. All links will be relative to http://cvs.sslug.dk/linuxbog. It will also create a file with all the log data in it, in chronological order. AUTHORS
The cvs2html script was written by Peter Toft and others (see the comments in /usr/bin/cvs2html for an exhaustive list). This manual page was written by Antti-Juhani Kaijanaho for Debian GNU, and modified by Pascal Hakim. SEE ALSO
The file /usr/share/doc/cvs2html/help.txt. The source code to cvs2html, in /usr/bin/cvs2html. cvs(1) Debian Project 1999-12-10 CVS2HTML(1)
All times are GMT -4. The time now is 12:33 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy