Return error if - or certain characters are present in a list of strings


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Return error if - or certain characters are present in a list of strings
# 1  
Old 03-06-2012
Return error if - or certain characters are present in a list of strings

I have a list of strings, for example:

Code:
set strLst = "file1 file2 file3 file4"

I want to log an error if some of the fields happen to begin with -, or have characters like ; : ' , ? ] { =

Which means for example setting
Code:
set ierr = 1

# 2  
Old 03-07-2012
Code:
for i in $strLst
> do
> tmp=`(echo $i | grep ^-) || (echo $i | grep "[; : ' , ? { = ]")`
> if [ "x$tmp" != "x" ]; then
> ierr=1
> fi
> done

# 3  
Old 03-07-2012
Okay, I want to simplify on this.

I just want that the entries and alphanumeric.

Want to allow only the following

a-z,A-Z,numbers,spaces and -

---------- Post updated at 08:55 AM ---------- Previous update was at 08:46 AM ----------

I have created code like this

Code:
set errLst = ""
foreach f ($arg_browseFilesLst)
  set cerr = `echo "$f" | grep "[ ; : ' , ? { } $ = ]"`
  set cerr = `echo $f | awk '/^-|=/'`
  if (${%cerr} > 0) then                            # Matches '-' at beginning or '='
    set errLst = "$errLst $f"
    set ierr = 1
  endif
end

But I really am thinking of only allowing alphanumeric strings and punctuation characters, using
Code:
[:alnum:]

and
Code:
[:punct:]

[/CODE] and also not allowing - at the beginning of the string, and the = sign.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to pass strings from a list of strings from another file and create multiple files?

Hello Everyone , Iam a newbie to shell programming and iam reaching out if anyone can help in this :- I have two files 1) Insert.txt 2) partition_list.txt insert.txt looks like this :- insert into emp1 partition (partition_name) (a1, b2, c4, s6, d8) select a1, b2, c4, (2 Replies)
Discussion started by: nubie2linux
2 Replies

2. Shell Programming and Scripting

Shell Scripting | Return list of unique characters in files

Hi, I am trying to script the below, but I am not very good at it :( Your help would be greatly appreciated. 1. read all files in the directory in strings strings *.* 2. in each file, for each line that contains "ABCD", store characters located at position 521 and 522 of this line... (9 Replies)
Discussion started by: clippertm
9 Replies

3. Shell Programming and Scripting

List file NOT present in other directory

Dear community, I have one LOG directory with some files. What I need to do is list ONLY the files that are not present in other directory. Using Bash programming! LOG DIR | SYNC DIR FILE1 | FILE1 FILE2 | FILE3 FILE3 | OTHER FILENAME FILE4 ... (9 Replies)
Discussion started by: Lord Spectre
9 Replies

4. Shell Programming and Scripting

Bash function accepting list of strings and error message

I have a variable strLst containing a list of strings. I want to create a function that takes the list and an error message. If the number of strings is 0 or greater than 1, I print the error message. (1 Reply)
Discussion started by: kristinu
1 Replies

5. UNIX for Dummies Questions & Answers

Delete strings in file1 based on the list of strings in file2

Hello guys, should be a very easy questn for you: I need to delete strings in file1 based on the list of strings in file2. like file2: word1_word2_ word3_word5_ word3_word4_ word6_word7_ file1: word1_word2_otherwords..,word3_word5_others... (7 Replies)
Discussion started by: roussine
7 Replies

6. Shell Programming and Scripting

Help to find string and return following characters from list of files

Hi, I'm fairly new to UNIX, but hopefully some-one can help me with this: I am using the following code to find files with the name "example.xml": find . -name "example.xml" -print that would print me a list like the example here: ./dir1/dir2/example.xml... (5 Replies)
Discussion started by: boijie
5 Replies

7. Shell Programming and Scripting

How to run a loop for assigning strings which are present in a file to an array

Hi Forum, I am struggling with the for loop in shell script. Let me explain what is needed in the script. I have a file which will conatin some strings like file1 place1 place2 place3 checkpoint some other text some more text Now what my requirement is the words ... (2 Replies)
Discussion started by: siri_14
2 Replies

8. Shell Programming and Scripting

Delete Strings that are present in another file

HI, if a String is present in file1.txt, i want to delete that String from file2.txt. How can i do this?? I am sure that the file1.txt is a subset of file2.txt. (2 Replies)
Discussion started by: jathin12
2 Replies

9. UNIX for Dummies Questions & Answers

How one can list only the name of directories present in the directory by using ls co

How one can list only the name of directories present in the directory by using ls command. (2 Replies)
Discussion started by: amolpatil54321
2 Replies
Login or Register to Ask a Question