Inconsistent behaviour of sed - UNIX AIX 5.3


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Inconsistent behaviour of sed - UNIX AIX 5.3
# 1  
Old 02-14-2013
Bug Inconsistent behaviour of sed - UNIX AIX 5.3

Hi there.

I'm facing a strange & an intriguing behaviour with sed while replacing the tab character with a space reading from a file. It randomly works sometimes but mostly doesn't work.

Below is what's happening-

<tab> here is the actual literal tab.

user1> cat temp2
1<tab>2<tab>3 4 5<tab>6
<tab>1 2<tab>3<tab><tab>4<tab>5 6

user1> sed 's/<tab>/ /g' temp2 ------> Did NOT work here
1<tab>2<tab>3 4 5<tab>6
<tab>1 2<tab>3<tab><tab>4<tab>5 6

user1> sed 's/<tab>/ /g' temp2 ------> Worked this time
1 2 3 4 5 6
1 2 3 4 5 6

user1> sed 's/<tab>/ /g' temp2 ------> Worked again
1 2 3 4 5 6
1 2 3 4 5 6

user1> sed 's/<tab>/ /g' temp2 ------> Did NOT work here
1<tab>2<tab>3 4 5<tab>6
<tab>1 2<tab>3<tab><tab>4<tab>5 6

user1> sed 's/<tab>/ /g' temp2 ------> Did NOT work here
1<tab>2<tab>3 4 5<tab>6
<tab>1 2<tab>3<tab><tab>4<tab>5 6

user1> sed 's/<tab>/ /g' temp2 ------> Did NOT work here
1<tab>2<tab>3 4 5<tab>6
<tab>1 2<tab>3<tab><tab>4<tab>5 6


I did not change the temp2 file in any manner whatsoever throughout the above steps.

Anyone got any idea about this???

Thanks,
Deepak.D

Last edited by Deepak.Dhami; 02-14-2013 at 09:08 PM..
# 2  
Old 02-14-2013
Please put [code] and [/code] tags around your data so the forum doesn't change the format.

I'd also suggest you use /usr/bin/sed on command line to avoid any possibility on aliases or PATH changes causing you to use a non-standard sed.

Also pipe output to od -c to ensure we see non printables eg:

Code:
$ od -c temp2
0000000    1  \t   2  \t   3       4       5  \t   6  \n  \t   1       2
0000020   \t   3  \t  \t   4  \t   5       6  \n
0000032
$ /usr/bin/sed "s/$(printf "\t")/ /g" temp2 | od -c
0000000    1       2       3       4       5       6  \n       1       2
0000020        3           4       5       6  \n
0000032

This User Gave Thanks to Chubler_XL For This Post:
# 3  
Old 02-14-2013
Thank you Chubler_XL, your suggestion works & is also consistent.
Code:
user1> sed "s/$(printf "\t")/ /g" temp2
1 2 3 4   5 6
 1  2 3 4  5 6
1 2 3 4   5 6
 1  2 3 4  5 6

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk Strange behaviour in AIX

Can someone please explain the strange behaviour.. I was just trying a few things to learn awk.. in the below code when I start the braces in the same line, the output is as expected, when I start at next line, output is displayed twice. Please see the file, code I tried and output below. ... (2 Replies)
Discussion started by: Kulasekar
2 Replies

2. Shell Programming and Scripting

sed Command not working in AIX UNIX

Hi 1st problem -------------- i have this sed command in my unix script which replaces new line and carriage return in a line with the string "&#xA" the script works fine in Linux 3.0.101-0.5, but not in AIX 1 7 , the "s/\r/\&#xA/g" replacement, replaces all the character "r" in the file.... (3 Replies)
Discussion started by: maximus_jack
3 Replies

3. Shell Programming and Scripting

Korn shell behaviour in AIX

Hi, Consider the code snippet below: fun() { while read x do echo $x done < somefile_that_does_not_exists } fun echo I am here Korn shell on HPUX prints the message "I am here", while the behaviour is different on AIX korn shell. We do not get the message on AIX. Any... (5 Replies)
Discussion started by: 116@434
5 Replies

4. Shell Programming and Scripting

Explanation for interesting sed behaviour?

This is my first post so hi to you all. I have browsed these forums in the past and what a great community and resource this is! Thanks to all the contributors ... I look forward to being able to give something back. In the meantime, I have a little conundrum concerning sed. My very simple... (6 Replies)
Discussion started by: Gavster
6 Replies

5. HP-UX

Why are these inconsistent?

Hi I am using HP - UX... When I execute the below commands I get these results... Why do i get a different shell value when i run echo $SHELL? # echo $0 ksh # echo $SHELL sh # ps -p$$ PID TTY TIME COMMAND 4013 pts/7 0:00 ksh (2 Replies)
Discussion started by: gurubarancse
2 Replies

6. Shell Programming and Scripting

unix "trap" command behaviour

Hi I am using "trap" command in my script to prevent the user from running Ctrl-C during the its execution. My script creates number of children processes which in turn create some children processes as well during the execution. When user / tester tries to run Ctrl-C, the parent process is... (1 Reply)
Discussion started by: aoussenko
1 Replies

7. Shell Programming and Scripting

strange behaviour from sed???

Hi all, I want to do a very simple thing with sed. I want to print out the line number of a disk I have defined in /etc/exports, so I do: It's all good, but here's the problem. When I define md0 in a variable, I get nothing from sed: Why is that? can anybody please help? Thanks (2 Replies)
Discussion started by: alirezan
2 Replies

8. Shell Programming and Scripting

Weird sed behaviour in script

I've written a small script to replace certain words in all the the files in a directory. #!/bin/sh #Get list of files to be edited file_list=`ls -p` for i in $file_list do echo "Processing $i" alteredi=`echo "$i" | sed -e 's/\//d/'` if then if then #actual altering (2 Replies)
Discussion started by: Peetrus
2 Replies

9. UNIX for Advanced & Expert Users

Strange sed behaviour

$ echo a.bc | sed -e "s/\|/\\|/g" |a|.|b|c| $ Is the behavior of the sed statement expected ? Or is this a bug in sed ? OS details Linux 2.6.9-55.0.0.0.2.ELsmp #1 SMP Wed May 2 14:59:56 PDT 2007 i686 i686 i386 GNU/Linux (8 Replies)
Discussion started by: vino
8 Replies

10. UNIX for Dummies Questions & Answers

very strange behaviour on unix server

Hi guys, im encountering some very strange behaviour (intermittently) when visiting my domain. We have a dedicated unix server hosting a number of sites with the problem currently reported on one site. I go to mydomain.com, and am directed to http://www.mydomain.com/?fnf=1 Classified ads... (7 Replies)
Discussion started by: bolo77
7 Replies
Login or Register to Ask a Question