Confirming a string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Confirming a string
# 1  
Old 02-26-2013
Confirming a string

Hi Guys,

I have files that are sent to me in this format:

Code:
Copy of USer Database updated 23 JANUARY 2013.csv

I am developing a script to load these files to my database automatically whenever I get these files:

How do I verify these files in an if statement if I do have these files?

Code:
if [ -e  'Copy of USer Database updated 23 JANUARY 2013.csv' ]

then

But the issue is that I need to have something like this:

Code:
if [ -e Copy of USer Database updated* ]

or something similar

But it does not seem to be possible, I tried these

Code:
ls -ltrh 'Copy of USer Database updated*'

ls: Copy of USer Database updated*: No such file or directory

Please Help...

Thanks in advance.

Last edited by Scrutinizer; 02-26-2013 at 06:08 AM.. Reason: code tags
# 2  
Old 02-26-2013
Are you sure this is the name of your file

Code:
Copy of USer Database updated 23 JANUARY 2013.csv

I don't think shell can read this file. It should be like this
Code:
Copy_of_USer_Database_updated_23_JANUARY_2013.csv

.

In which directory you have this file. Check that directory and give
Code:
ls

. And let us know what your are getting.

Last edited by Vikram_Tanwar12; 02-26-2013 at 10:20 AM..
# 3  
Old 02-26-2013
Try:

Code:
ls -ltrh 'Copy of USer Database updated'*

or:

Code:
exists() {
  [ -e "$1" ]
}

if exists 'Copy of USer Database updated'*
then
  ..

# 4  
Old 02-26-2013
Hi
this is one way
Code:
ls Copy\ of\ USer\ Database\ updated*.csv   > /dev/null 2>&1
if [ $? -eq 0 ]
then
echo "File exists"
else
echo "File not exists"
fi

# 5  
Old 02-26-2013
As a very wild guess, are you sure that you have the correct name. Have you tried:
Code:
if [ -e  'Copy of User Database updated 23 JANUARY 2013.csv' ]

If this doesn't solve the problem, please show us the output from the command:
Code:
ls -ld Copy*

# 6  
Old 02-26-2013
Lightbulb

Quote:
Originally Posted by Phuti
Hi Guys,

I have files that are sent to me in this format:

Code:
Copy of USer Database updated 23 JANUARY 2013.csv

I am developing a script to load these files to my database automatically whenever I get these files:

How do I verify these files in an if statement if I do have these files?

Code:
if [ -e  'Copy of USer Database updated 23 JANUARY 2013.csv' ]

then

But the issue is that I need to have something like this:

Code:
if [ -e Copy of USer Database updated* ]

or something similar

But it does not seem to be possible, I tried these

Code:
ls -ltrh 'Copy of USer Database updated*'
 
ls: Copy of USer Database updated*: No such file or directory

Please Help...

Thanks in advance.

Try this

Code:
 
ls -ltrh 'Copy of USer Database updated'*

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Search a string and display its location on the entire string and make a text file

I want to search a small string in a large string and find the locations of the string. For this I used grep "string" -ob <file name where the large string is stored>. Now this gives me the locations of that string. Now how do I store these locations in a text file. Please use CODE tags as... (7 Replies)
Discussion started by: ANKIT ROY
7 Replies

2. Shell Programming and Scripting

Confirming validity of programming language tools

so i have scripts that get run in ways similar to this: cat script.pl | perl - $1 $2 $3 cat script.rb | ruby - $1 $ 2 $3 my question is, how can i verify that that the "perl" or "ruby" or "python" tool being run on the box is actually a legit tool? meaning, someone may move the tool from... (2 Replies)
Discussion started by: SkySmart
2 Replies

3. Shell Programming and Scripting

Remove lines between the start string and end string including start and end string Python

Hi, I am trying to remove lines once a string is found till another string is found including the start string and end string. I want to basically grab all the lines starting with color (closing bracket). PS: The line after the closing bracket for color could be anything (currently 'more').... (1 Reply)
Discussion started by: Dabheeruz
1 Replies

4. Shell Programming and Scripting

grep exact string from files and write to filename when string present in file

I am attempting to grep an exact string from a series of files within a directory and append that output to the filename when it is present in the file. I've been after this all day with no luck. Thanks for your help in advance :wall:. (4 Replies)
Discussion started by: JC_1
4 Replies

5. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

6. Shell Programming and Scripting

to extract string from main string and string comparison

continuing from my previous post, whose link is given below as a reference https://www.unix.com/shell-programming-scripting/171076-shell-scripting.html#post302573569 consider there is create table commands in a file for eg: CREATE TABLE `Blahblahblah` ( `id` int(11) NOT NULL... (2 Replies)
Discussion started by: vivek d r
2 Replies

7. AIX

Confirming command

Guy's I'm trying to create script to execute some critical commands in AIX like the below ... stopsrc -s qdaemon stopsrc -s sshd stopsrc -s lpd stopsrc -s nfsd I want between each command to ask me like this " are you sure to stop qdaemon " " are you sure to stop ssh" " are... (3 Replies)
Discussion started by: Mr.AIX
3 Replies

8. IP Networking

Confirming Successful Server/Device Reboot

Hello I've created a list with IP address to servers/devices I would like to reboot and have logged the following to the /tmp before: -netstat -nrv -/etc/rc2.d/netmask -/etc/rc2.d/defaultrouter -ifconfig -a I would like to confirm that nothing changed after the reboot. I know this can be... (0 Replies)
Discussion started by: ravzter
0 Replies

9. Shell Programming and Scripting

Confirming Remote Copy

Hey guys. I'm knocking up a script, a part of which will be copying some pretty large files to some remote servers. With the size of the files I need to make sure that they don't lose any data / corrupt on the way (it's unlikely, but these are business critical). Obviously I could use the... (2 Replies)
Discussion started by: dlam
2 Replies

10. Shell Programming and Scripting

Confirming Syntax - IF statement.

Hi All, Has been a while since I was last on, so I hope everyone has been doing fine. ;) Would like to know if the below IF statement syntax is correct for a ksh environment. It's been pushed into live as someone had deleted the development copy(!); not withstanding that, the statement now... (3 Replies)
Discussion started by: Cameron
3 Replies
Login or Register to Ask a Question