Sponsored Content
Top Forums Shell Programming and Scripting Script to List, Modify, replace filename for an upload? Post 302557622 by cfajohnson on Wednesday 21st of September 2011 05:30:31 PM
Old 09-21-2011
Quote:
Originally Posted by shadok
Hello,

I tried your solution but apprently, the test doesn't work well since no action that have to be done if the "if" test are done.

I tried to replace the test from
Code:
if [ -f $target_file]

to

Code:
if [test -f $target_file]

but it says
Code:
./upload.sh: 25: [test: not found

So, what should I do to test properly the existence of the file ?

Both [ and test are the same command.

Code:
if test -f "$target_file"

or:
Code:
if [ -f "$target_file" ]  ## spaces are required

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how can i add/modify filename after output?

Hi All, I have a script to convert a file and output the filename with "_output", however it not work. Can help? echo Please input list file name: read listn for file in `cat $listn.txt` do convert $file > $file_output Thanks all!! (3 Replies)
Discussion started by: happyv
3 Replies

2. Shell Programming and Scripting

read a part of filename from the list in the script

how can i read a part of filename from the list in the script? all file in directory...will start with "CDBACKUPFILE" then the name is stored in list.txt such as JOHN,MARRY,PETER. After this, is seq number. CDBACKUPFILEJOHN00001 CDBACKUPFILEMARRY00004 CDBACKUPFILEPETER00003 I will use:... (3 Replies)
Discussion started by: happyv
3 Replies

3. Shell Programming and Scripting

Request to modify script to list multiple parameters for V_fieldid variable

I am posting a script below which essentially excutes the following functions in the described order. 1) From a source directory pools together three files generated by system logs for each user session, tar's these files and archives them as a log set in a destination directory and these... (0 Replies)
Discussion started by: Sammy
0 Replies

4. UNIX for Dummies Questions & Answers

Replace all files with a certain filename with another file

I tried searching for this, but I might have used the wrong terms as I couldn't find answers to this question. I'm looking for a way to replace all files with a certain filename with another file within a specific directory including all of it's subdirectory using a shell-script. (2 Replies)
Discussion started by: Schmellsera
2 Replies

5. Shell Programming and Scripting

Replace text with filename

Hi, I have a few thousand files, each contains the word "hello". Would it be possible to do a batch job that replaces the word hello with the filename? Thanks. (2 Replies)
Discussion started by: calrog
2 Replies

6. Shell Programming and Scripting

List files and display last modify time in a particular format

hi everyone, can someone suggest how i can list the contents of a directory and display their corresponding last modify time in the format yyyymmddhhmm? thanks in advance! (16 Replies)
Discussion started by: Deanne
16 Replies

7. Shell Programming and Scripting

Modify sources.list from script

i'm looking for a way to enable and disable repositories from a script. i started with a sed command like this: sed '/*'"$REPO"'/,/'"$STOP"'/ s/^*//' /etc/apt/sources.list but this enables both the normal and the source repos. for example: # deb http://www.lamaresh.net/apt lenny main #... (7 Replies)
Discussion started by: Leppie
7 Replies

8. Shell Programming and Scripting

sed to replace pattern with filename

Hi all, I'm trying to replace a pattern/string in about 100 files with the filename using following commands but getting nowhere: for f in *.fa; do sed "s/^>.*/>$f/g" $f > $f_v1.fa; done for f in *.fa; do sed 's/^>.*/>`echo $f`/' > $fa_v1.fa; done Basically I want to change any line... (5 Replies)
Discussion started by: ivpz
5 Replies

9. Shell Programming and Scripting

Help shell script to list filename file_path

HI owner date and time and size of file in a row shell script to list filename file_path i have tried the below code present_dir=`pwd` dir=`dirname $0` list=`ls -lrt | awk {'print $9,$3,$6,$7,$8'}` size=`du -h` path=`cd $dir;pwd;` printf "$list" printf "$path" printf " $size" ... (4 Replies)
Discussion started by: abiram
4 Replies

10. UNIX for Dummies Questions & Answers

To replace a filename

Hi i want to replace date stamp filename to original file name. i want to remove the datestamp after .txt For eg: file_name.txt_01-1002014 output: file_name.txt tried with below one but not able to achieve mv file_name.txt_01-1002014`basename "file_name.txt_01-1002014 "`.txt (4 Replies)
Discussion started by: rohit_shinez
4 Replies
COMBINE(1)																COMBINE(1)

NAME
combine - combine sets of lines from two files using boolean operations SYNOPSIS
combine file1 and file2 combine file1 not file2 combine file1 or file2 combine file1 xor file2 _ file1 and file2 _ _ file1 not file2 _ _ file1 or file2 _ _ file1 xor file2 _ DESCRIPTION
combine combines the lines in two files. Depending on the boolean operation specified, the contents will be combined in different ways: and Outputs lines that are in file1 if they are also present in file2. not Outputs lines that are in file1 but not in file2. or Outputs lines that are in file1 or file2. xor Outputs lines that are in either file1 or file2, but not in both files. "-" can be specified for either file to read stdin for that file. The input files need not be sorted, and the lines are output in the order they occur in file1 (followed by the order they occur in file2 for the two "or" operations). Bear in mind that this means that the operations are not commutative; "a and b" will not necessarily be the same as "b and a". To obtain commutative behavior sort and uniq the result. Note that this program can be installed as "_" to allow for the syntactic sugar shown in the latter half of the synopsis (similar to the test/[ command). It is not currently installed as "_" by default, but you can alias it to that if you like. SEE ALSO
join(1) AUTHOR
Copyright 2006 by Joey Hess <joey@kitenet.net> Licensed under the GNU GPL. moreutils 2012-04-09 COMBINE(1)
All times are GMT -4. The time now is 09:12 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy