Issue with Sed command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Issue with Sed command
# 8  
Old 07-07-2011
The xml file contains,
<?xml version="1.0" encoding="UTF-16"?>

here the code should search for this UTF-16 keyword and if found then need to convert the encoding to UTF-8 and then i want to replace this UTF-16 keyword to UTF-8.
Please help.
# 9  
Old 07-07-2011
grep command is working for me
Code:
 
 
$ grep "UTF\-16" test.xml
<?xml version="1.0" encoding="UTF-16"?>

Did you change the agrs to args ? ( the typo in the last post )

Code:
 
for i in `find . -type f | xargs grep -l "UTF\-16"`
do
iconv -f UTF-16 -t UTF-8 $i > $i.old
sed 's/UTF-16/UTF-8/g' $i.old > $i
rm -f $i.old
done

# 10  
Old 07-07-2011
Hi,

but grep "UTF\-16" filename
is not fetching any result for me if i try on the xml extension files.

If i try with sed -n '/UTF-16/p' filename it is working for individual file but for a number of files this command is not working.
# 11  
Old 07-07-2011
you can use

are you using solaris ?

Code:
 
$ /usr/xpg4/bin/grep "UTF.16" test.xml
<?xml version="1.0" encoding="UTF-16"?>

# 12  
Old 07-07-2011
Quote:
Originally Posted by itkamaraj
grep command is working for me
Code:
 

$ grep "UTF\-16" test.xml
<?xml version="1.0" encoding="UTF-16"?>

Perhaps the backslash before the dash is the problem. Since the dash is not in any way special outside of a bracket range expression, technically that's an undefined sequence. Posix basic and extended regular expression implementations are allowed to behave differently when such a sequence is encountered. The implementation may throw a syntax error, discard the backslash and match the dash, match a literal backslash followed by a dash, or ask your cpu to self-destruct. It's best not to escape characters which are not special.

In the posix extended regular expression flavor, there are no ordinary characters which may be portably preceded by a backslash. In the posix basic regular expression flavor, there are only a few exceptions and dash outside of a bracket expression is not one of them: (, ), {, }, digits 1 through 9, and anything inside a bracketed expression.

For more info, see section 9.3.2 and 9.4.2 @ Regular Expressions

Regards,
Alister

Last edited by alister; 07-07-2011 at 08:44 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Issue with sed command

Hi, I have a script that replaces one string with the other in all files under the specified directory. !/bin/bash # **************** Change Variables Here ************ startdirectory="/opt/app/properties/tmp_new" searchterm="Oracle/Middleware/" replaceterm="" #... (1 Reply)
Discussion started by: mohtashims
1 Replies

2. Shell Programming and Scripting

sed command issue in script

Hi, I am using sed command to extract data from my log file for a certain time interval. From and To "time" are my input arguments. Now if i use the sed command on command line. I get the desired results and If i use it in script.It fails. sed command as command line: sed -n '/04-Mar-2015... (6 Replies)
Discussion started by: oberoi1403
6 Replies

3. UNIX for Dummies Questions & Answers

Issue with sed command

Hi, I want to use a code like sed -n "1,9988p" filename | wc -l I tried from=1 till=9988 sed -n "/$from/,/$till/p" filename |wc -l Issue: sed -n "1,9988p" filename | wc -l -- Returns 9988 rows But sed -n "/$from/,/$till/p" filename |wc -l # Returns > 9988 rows(Complete file) I... (2 Replies)
Discussion started by: Gurkamal83
2 Replies

4. Shell Programming and Scripting

Issue with SED command

I have a file that contains lines like this: allgroups: cn=Role1,cn=groups,o=xyz,st=mn,c=us allgroups: cn=Role1,cn=groups,o=xyz,st=mn,c=us I want to remove the string : ,cn=groups,o=xyz,st=mn,c=us and so I tried to use SED. i tried to assign it to a variable and use it: ... (3 Replies)
Discussion started by: vskr72
3 Replies

5. Shell Programming and Scripting

Issue in using variable within sed command

Hi All, I am trying to use a variable within the sed command but I am not able to get the output. When I am using the following command (without variable) its working fine: sed -n '/2011\/12\/10 18:11:11./,$p' < Log.txt > Delta_Log.txt But when I am putting the value 2011\/12\/10... (4 Replies)
Discussion started by: acoomer
4 Replies

6. Shell Programming and Scripting

Sed command issue in linux

I ran one the script in debug mode in linux and have a problem ret='$prmAttunityUser=ais' Now i need to remove $ from this '$prmAttunityUser=ais' so i had added a sed command like this sed 's/$//g' but its not working could you all please help me with an alternate command I want the output... (3 Replies)
Discussion started by: vee_789
3 Replies

7. UNIX for Dummies Questions & Answers

Sed Command Issue

Hello, I want to remove the / found when executing the date command. When I use: date +%D | sed 's/\///' I get: 1105/09 I tried: date +%D | sed 's/\*$///' I need to remove all / from the date command, but it does not seem to work (5 Replies)
Discussion started by: mojoman
5 Replies

8. Shell Programming and Scripting

sed command issue

Hi everybody, I have come across a typical problem: I need to use sed command to replace an apostrophe but it is saying no match found in the error sed -e 's/`/'/g' ...but it is not working. Can you please tell me how to use this apostrophe in this sed command please. Thanks. Rubin (8 Replies)
Discussion started by: RubinPat
8 Replies

9. UNIX Desktop Questions & Answers

Issue with sed command

Hi, I have to replace the character AL2 with AL16 which I have in one of my text file . I used the sed command like this sed 's/sed 's/AL2/AL16/g' test_carr.dat>test_carr1.dat But it is not replacing this value to the output file. The test_carr.dat file contains data like this cat... (1 Reply)
Discussion started by: kavithakuttyk
1 Replies

10. Shell Programming and Scripting

Issue with Sed Command

Hello , I am trying to replace a word :: complete to Failed . work: complete Sed command which i am using is given below :: sed s/work: complete/Failed/g temp1.txt > temp2.txt (Sed command is grabled if i use the above .. because of space which is there between work: and complete. I... (6 Replies)
Discussion started by: raghav1982
6 Replies
Login or Register to Ask a Question