comparing special characters in KSH


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting comparing special characters in KSH
# 1  
Old 10-26-2012
comparing special characters in KSH

Hi Guys,

I came across a scenario where I have to check the starting character of line in a file.
if it is a specile character i.e. "<" gretaer then perform action.
I tried serval ways but could not get the work done.

Please help me ....
Thanks
# 2  
Old 10-26-2012
< is less-than. You mean >?

Which line? All of them, any of them, or a specific one?
# 3  
Old 10-26-2012
All the lines starting with either greater than or lesser than symbol......"<" or ">".
where I should process line by line...
# 4  
Old 10-26-2012
Code:
$ cat file1
< line 1
sdasd
asdadasd
> line 4
< line 5
---- > line 6

$ cat myScript
while read LINE; do
  if [[ $LINE =~ '^<' ]] || [[ $LINE =~ '^>' ]]; then
    echo $LINE
  fi
done < file1

$ ./myScript
< line 1
> line 4
< line 5

# 5  
Old 10-26-2012
comparing special charactes in KSH

Hi Scott,

I tried with the code but it is throwing an error as below

test.ksh[2]: syntax error at line 3 : `=~' unexpected

I am using KSH ...please let me know any suggestions

---------- Post updated at 10:49 AM ---------- Previous update was at 10:45 AM ----------

My questions is I should have a condition in IF clause to compare special character like greater than and lesser than symbols which should be used for line by line processing in KSH

File

<line1
<line2
-----<line3
<line4
askjler
lkajwoie
>line5

output expected

<line1
<line2
<line4
>line5
# 6  
Old 10-26-2012
Code:
while read line
do
   if [ `echo ${line} | egrep "^\<|^\>" | wc -l` -eq 0 ]
   then
         :
   else
         echo $line
   fi
done < file

# 7  
Old 10-26-2012
Code:
while read line
do
 if [[ $line == @(<*|>*) ]]
 then
  echo $line
 fi
done < file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace special characters with Escape characters?

i need to replace the any special characters with escape characters like below. test!=123-> test\!\=123 !@#$%^&*()-= to be replaced by \!\@\#\$\%\^\&\*\(\)\-\= (8 Replies)
Discussion started by: laknar
8 Replies

2. Shell Programming and Scripting

Replace special characters

I have a line ending with special character and 0 The special character is the field separator for this line in VI mode the file will look like below, but while cat the special character wont display i know the hexa code for the special character ^_ is \x1f and ascii code is \0037, ... (0 Replies)
Discussion started by: ratheeshjulk
0 Replies

3. Shell Programming and Scripting

special characters

Hey guys, I'm trying to replace "]Facebook" from the text but sed 's/]Facebook/Johan/g' is not working could you please help me with that? (6 Replies)
Discussion started by: Johanni
6 Replies

4. UNIX for Dummies Questions & Answers

How to see special characters?

Hi all, I was wondering how can i see the special characters like \t, \n or anything else in a file by using Nano or any other linux command like less, more etc (6 Replies)
Discussion started by: gvj
6 Replies

5. Shell Programming and Scripting

remove special characters

hello all I am writing a perl code and i wish to remove the special characters for text. I wish to remove all extended ascii characters. If the list of special characters is huge, how can i do this using substitute command s/specialcharacters/null/g I really want to code like... (3 Replies)
Discussion started by: vasuarjula
3 Replies

6. Shell Programming and Scripting

Special characters

When I open a file in vi, I see the following characters: \302\240 Can someone explain what these characters mean. Is it ASCII format? I need to trim those characters from a file. I am doing the following: tr -d '\302\240' ---------- Post updated at 08:35 PM ---------- Previous... (1 Reply)
Discussion started by: sid1982
1 Replies

7. Shell Programming and Scripting

sed with many special characters

I started with this: counter1=1 cp file.txt file_${counter1}.tmp while read name1 do echo $name1 counter2=`expr $counter1 + 1` sed /'${name1}'/d file_${counter1}.txt > file_${counter2}.txt counter1=`expr $counter1 + 1` done < source.txtsource.txt contains the... (1 Reply)
Discussion started by: lakanino
1 Replies

8. Shell Programming and Scripting

Escaping Special Characters-Help

Hi All, I am having a trouble in passing special characters to a script. As I am new to bash script I dont know how to go and solve this. mypwd=(a+sdfg!h# if i pass $mypwd to a bash script, it is not accepting "(,!,+ etc". It would be a great help if some one can help to escape these... (3 Replies)
Discussion started by: Tuxidow
3 Replies

9. UNIX for Dummies Questions & Answers

Comparing Special characters (i.e. -,\,/) in an if statment

I need to validate the special characters of a date (the characters between the year and month & month and day). The data filed is being populated by users and read into the script vi an argument. I want to ensure that the date is a '-' (dash) and not a '/' or '\' (slash). The every thing I... (3 Replies)
Discussion started by: angelap
3 Replies

10. UNIX for Dummies Questions & Answers

special characters

I have one file which is named ^? ( the DEL character ) I'd like to know how to rename or copy the file by using its i-node number TYIA (2 Replies)
Discussion started by: nawnaw
2 Replies
Login or Register to Ask a Question