How do I test if a file contains particular characters


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How do I test if a file contains particular characters
# 1  
Old 04-22-2009
How do I test if a file contains particular characters

I am trying to write a bash script but do not know the unix commands I will have to use. I first have to test if an input file contains a number of characters.

For instance My input file's name is dunne.
cat dunne is bbcddceeceecbbacadce

So I want to test the out put of my file to see if it contains the characters abcde only.

if it does I will proceed with other commands,
if it does not, I will have to terminate.

I will appreciate any help on this.
# 2  
Old 04-22-2009
Hi,
could U write the example in detail i.e Input file and desired output U want with performed operation.
# 3  
Old 04-22-2009
ok Kaprus,

The input file(dunne) is a one line string without spaces eg:

bbcddceeceecbbacadce.

The script should test if these characters: 'a' 'b' 'c' 'd 'only are contained in the file(the characters may be repeated a number of times, doesn't matter).

If the input file contains string with only the characters 'a' 'b' 'c' 'd , then the script echo 'input file authentic'

if the file contains string with characters other than 'a' 'b' 'c' 'd then the script echo 'input file not authentic.

so if abbccddeebbd is input file

out put should be : input file authentic,

but if input file is abbgkfhccste

output should be: input file inauthentic

So the script should test if any input file contains string with only characters 'a' 'b' 'c' 'd

Thanks for your antcipated help.
# 4  
Old 04-22-2009
this smells like homework stuff which is not allowed by our rules! i'll close this one down.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to test that a string doesn't contain specific characters?

Hi ! :) I made this : #!/bin/bash rsa_dir="/etc/openvpn/easy-rsa/" rsa_key_dir="/etc/openvpn/easy-rsa/keys/" ccd_dir="/etc/openvpn/ccd/" regex_special_char='' cd $rsa_dir while read -p "Please can you enter the vpn's username : " username ] || ] || ] || ] do echo "Your entry... (10 Replies)
Discussion started by: Arnaudh78
10 Replies

2. Shell Programming and Scripting

Hit multiple URL from a text file and store result in other test file

Hi, I have a problem where i have to hit multiple URL that are stored in a text file (input.txt) and save their output in different text file (output.txt) somewhat like : cat input.txt http://192.168.21.20:8080/PPUPS/international?NUmber=917875446856... (3 Replies)
Discussion started by: mukulverma2408
3 Replies

3. Shell Programming and Scripting

A test command parameter is not valid, when special characters are tried to match

Hi I have a scenario where hyphen(-) from file should be ignored I used the following code if && ; then if ; then pow=$LINE echo $pow > history.txt flag=1 fi fi I get the following output ./valid.sh: -: 0403-012 A test... (7 Replies)
Discussion started by: Priya Amaresh
7 Replies

4. UNIX for Advanced & Expert Users

special characters in IF TEST

I'm using Korn shell. I'm doing an IF TEST for lots of characters and don't know how to also check for single quote and parentheses and slash. I'm reading a file and some records have garbage characters in them. The following works, but how do I add single quote, parentheses and slash to the IF... (3 Replies)
Discussion started by: sboxtops
3 Replies

5. Shell Programming and Scripting

Problem in test file operator on a ufsdump archive file mount nfs

Hi, I would like to ask if someone know how to test a files if exist the file is a nfs mount ufsdump archive file.. i used the test operator -f -a h almost all test operator but i failed file1=ufs_root_image.dump || echo "files doesn't exist && exit 1 the false file1 is working but... (0 Replies)
Discussion started by: jao_madn
0 Replies

6. Shell Programming and Scripting

How to check weather a string is like test* or test* ot *test* in if condition

How to check weather a string is like test* or test* ot *test* in if condition (5 Replies)
Discussion started by: johnjerome
5 Replies

7. Shell Programming and Scripting

Test on string containing spacewhile test 1 -eq 1 do read a $a if test $a = quitC then break fi d

This is the code: while test 1 -eq 1 do read a $a if test $a = stop then break fi done I read a command on every loop an execute it. I check if the string equals the word stop to end the loop,but it say that I gave too many arguments to test. For example echo hello. Now the... (1 Reply)
Discussion started by: Max89
1 Replies
Login or Register to Ask a Question