Find invalid character


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find invalid character
# 15  
Old 10-29-2014
sorry chubler, can you please explain in brief.
Code:
&& c=\\"$c"

Code:
"${v/$c/}"

# 16  
Old 10-29-2014
Code:
&& c=\\"$c"

Interpretation: If the proceeding command returned true, then append backslash to the c variable

This line [[ "$c" = '\' || "$c" = '?' ]] && c=\\"$c"

could also be written as:
Code:
if [[ "$c" = '\' ]] || [[ "$c" = '?' ]]
then
    c='\'"$c"
fi

"${v/$c/}" replace 1st occurrence of $c within $v with nothing example:

Code:
$ v="the quick brown fox"
$ c=" quick"
$ echo "${v/$c/}"
the brown fox


Last edited by Chubler_XL; 10-29-2014 at 09:18 PM.. Reason: Correct typos
# 17  
Old 10-29-2014
thanks a lot, can you please help me where i can learn these such topic, i want to go through in detail,

i have ran script and looks like it is working, but i need to check with my manger tomorrow.

Can i ping you tomorrow , if i have any issue
# 18  
Old 10-29-2014
You should always start with the bash man entry for example Pattern subsitution:

Code:
       ${parameter/pattern/string}
              Pattern substitution.  The pattern is expanded to produce a pat-
              tern  just  as in pathname expansion.  Parameter is expanded and
              the longest match of pattern against its value is replaced  with
              string.   If  pattern  begins with /, all matches of pattern are
              replaced  with  string.   Normally  only  the  first  match   is
              replaced.  If pattern begins with #, it must match at the begin-
              ning of the expanded value of parameter.  If pattern begins with
              %,  it must match at the end of the expanded value of parameter.
              If string is null, matches of pattern are deleted and the / fol-
              lowing pattern may be omitted.  If parameter is @ or *, the sub-
              stitution operation is applied to each positional  parameter  in
              turn,  and the expansion is the resultant list.  If parameter is
              an array variable subscripted with  @  or  *,  the  substitution
              operation  is  applied  to each member of the array in turn, and
              the expansion is the resultant list.

If you are unsure how something will work try a small example from the command prompt as I did above.

I'll be around tomorrow and will check this thread for any further questions.
# 19  
Old 10-29-2014
Parameters Expansion Guide

Last edited by Aia; 10-29-2014 at 10:43 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Searching invalid character in list of client name

Hi Friend, I have a client name list and client name has some invalid character due to which some issue raised and list of client are15k. I want to make script who find invalid character name. can you please help me how i can make script, i means i need logic. Valid character are :- ... (5 Replies)
Discussion started by: pallvi_mahajan
5 Replies

2. AIX

Bison -pap_expr_yy invalid character:% unexpected "identifier" while running make for Apache2.4.3 64

The Follwing packages are installed on my AIX 6.1 box gcc-4.7.2-1 gcc-c++-4.7.2-1 gcc-cpp-4.7.2-1 gcc-gfortran-4.7.2-1 libgcc-4.7.2-1 libgomp-4.7.2-1 libstdc++-4.7.2-1 libstdc++-devel-4.7.2-1 gmp-5.0.5-1 libmpc-1.0.1-2 libmpc-devel-1.0.1-2 libmpcdec-1.2.6-1 libmpcdec-devel-1.2.6-1... (0 Replies)
Discussion started by: Ashish Gupta
0 Replies

3. Shell Programming and Scripting

Find character and Replace character for given position

Hi, i want find the character '-' in a file from position 284-298, if it occurs i need to replace it with 'O ' for the position in the file. How to do that using SED command. thanks in advance, Sara (9 Replies)
Discussion started by: Sara183
9 Replies

4. Shell Programming and Scripting

How to find invalid URL in a text file using shell script?

How to find and remove invalid URLs in a text file using shell script? (1 Reply)
Discussion started by: vel4ever
1 Replies

5. Shell Programming and Scripting

Find and replace a character

Hi Team, i have 1st cloumn of data containing, LAMSBA01-BA-COFF-YTD LAMSBA01-BA-COFF-ITD LAMSBA01-BA-AGGR-IND . LAMSBA01-BA-CURR-COFF-BAL i need to replace the "-" to "_" (underscore) using AWK . please help me on this. Thanks, Baski (4 Replies)
Discussion started by: baskivs
4 Replies

6. Solaris

An invalid XML character (Unicode: 0x1a)

While uploading an exl file to my application in Solaris 10 the upload failed with error Error! Parsing Error: /SPLM/TC83/tcdata83/model/model_dbextract.xml Line:65576 Column:73 An invalid XML character (Unicode: 0x1a) was found in the value of attribute "unitOfMeasureSymbol" and element is ... (12 Replies)
Discussion started by: karghum
12 Replies

7. UNIX for Dummies Questions & Answers

to find alphanumeric character

Hi All, I am having a data file which consists of lakhs of records in the below foramt: "1223323","4341341","discription aadfad" "3123123","5463456","discription aadfad" "2343324","6565767","discription asdfads" "A3423423","7957456","discription aadfad" "343453B","7957456","discription... (1 Reply)
Discussion started by: abhi_123
1 Replies

8. Linux

Invalid Character

Hi, I am using a Perl script to generate a report file in Linux server. When my input data contains an invalid character which looks like hyphen after that my program is printing junk values in the report. Why that symbol is causing issue and is there a way to tell the server that this is a valid... (1 Reply)
Discussion started by: lawrance_ps
1 Replies

9. Shell Programming and Scripting

Find ^M Character

Hi Experts, Is there a way to find whether a file contains ^M character in it?. It's quite obvious to vi, but can this be accomplished using an automated way to find recursively in a directory. probably i guess the best way would be to 1) Read the file and check if the end of line is ^M... (8 Replies)
Discussion started by: ganga.dharan
8 Replies

10. Shell Programming and Scripting

writing shell script to find line of invalid characters

Hi, I have to write s script to check an input file for invalid characters. In this script I have to find the exact line of the invalid character. If the input file contain 2 invalid character sat line 10 and 17, the script will show the value 10 and 17. Any help is appreciated. (3 Replies)
Discussion started by: beginner82
3 Replies
Login or Register to Ask a Question