sed Command not working in AIX UNIX


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed Command not working in AIX UNIX
# 1  
Old 04-22-2014
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.

Code:
sed "s/^M/\&#xA/g;s/\r/\&#xA\/g;s/\r^M/\&#xA/g"  < filename.txt > filename 2.txt

2nd problem
--------------
and then i have a awk command that works on the file filename2.txt (output of the above command), below is the awk command i'm using..

Code:
awk -v W="$1" '$0 ~ W{ORS="";if(NR!=1)print "\n";}1' filename2.txt > filename3.txt

instead of writing the sed output to a file can i send the output to the awk command, so that it doesn't have to take too much time writing and reading to two files.

any help is appreciated

Thanks
Mj
Moderator's Comments:
Mod Comment Please use CODE and ICODE tags to display sample code, input, and output.


---------- Post updated 04-22-14 at 08:06 AM ---------- Previous update was 04-21-14 at 06:17 PM ----------

Hi All
Any response would be appreciated....

thanks
MJ

Last edited by maximus_jack; 04-21-2014 at 08:42 PM.. Reason: Add CODE and ICODE tags.
# 2  
Old 04-22-2014
Looks like your shell and/or sed version don't take \r to represent the carriage return character. I think you need to resort to other representations, e.g <ctrl>v<ctrl>m or $'\r', or even a variable assigned from the output of a printf command.
For your second problem, why don't you just pipe sed's output to awk?

Last edited by RudiC; 04-22-2014 at 02:03 PM..
# 3  
Old 04-22-2014
You could use awk or perl to catch the \r etc. by it's octal value, which is 15 or \015 in this case.

An example:
Code:
$ od -c infile
0000000    s   t   a   r   t  \r  \n   s   t   o   p  \n
0000014
$ awk '{gsub(/\015/,"\&\#xA"); print}' infile > outfile
$ od -c outfile
0000000    s   t   a   r   t   &   #   x   A  \n   s   t   o   p  \n
0000017

There should be plenty of ascii tables with the octal values on the net.
Maybe you can do it all together with awk instead of sed. I assume there is a way with sed, but I don't know it.
# 4  
Old 04-22-2014
thanks rudic, i replaced /r with contorl M
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Working with if and sed in UNIX

I have a text file containing multiple lines like password="&test."; password="xyz"; password='write some'; password="&testwrite."; today='o1jan2017'd; ----------------- ------------------ I don't want to replace the string value which are starting with & for Password variable... (3 Replies)
Discussion started by: harshabag
3 Replies

2. UNIX for Beginners Questions & Answers

sed command not working

Hello There - Iam trying to get this expdp running for oracle backup. And this is the code below: ### Run the export. ### Comment out any LOGFILE parameters in the .par file. if grep -i "Logfile" /<Path>$1_$2_$3.par; then ## Comment out any LOGFILE... (7 Replies)
Discussion started by: bkilaru
7 Replies

3. Shell Programming and Scripting

Find command not working on AIX

Hello, I am running find command in an AIX Server to find last 7 days modified directories/files. >cd /usr/openv/netbackup/db/class >ls -l total 0 drwxr-xr-x 3 root system 256 May 28 2014 Catalog-Backup drwxr-xr-x 3 root system 256 Sep 18 2012 ... (4 Replies)
Discussion started by: rahul2662
4 Replies

4. Shell Programming and Scripting

Why is this command not working? (sed)

Hi guys, the command is echo "Online Memory : 32768 MB" | sed 's/.*\(+\).*/\1/' I would expect it to print 32768, it cuts off any character to the first digit, then gets all digits in 1, cuts off the rest after the digits, and should print 32768, instead it... (4 Replies)
Discussion started by: funksen
4 Replies

5. Shell Programming and Scripting

Maxdepth command not working in AIX.Need alternative solution for this command

Hi All, I am trying to select 30 days older files under current directory ,but not from subdirectory using below command. find <Dir> -type f -mtime + 30 This command selecting all the files from current directory and also from sub directory . I read some documention through internet ,... (1 Reply)
Discussion started by: kommineni
1 Replies

6. Shell Programming and Scripting

Sed script not working properly on Solaris (works fine on AIX)?

Hi, I have a problem with a SED script that works fine on AIX but does not work properly on a Solaris system. The ksh script executes the SED and puts the output in HTML in tables. But the layout of the output in HTML is not shown correctly(no tables, no color). Can anyone tell if there is... (7 Replies)
Discussion started by: Faith111
7 Replies

7. Shell Programming and Scripting

sed -i not working in HP unix

hi i want to append the number in each file,but when i ran this command:- sed -i "1i 50" filename its giving error sed: illegal option -- i in HP unix but its working in linux. any advice !!!!!!!!! (6 Replies)
Discussion started by: abhigrkist
6 Replies

8. AIX

prtconf command not working in Aix 5.3

put prtconf command,after show this error message: bash-3.00# prtconf /usr/sbin/prtconf: msize=msize + 12544^J12544: syntax error pleae help me...........waiting for replay by mohan.s Aix sysadmin (deleted email, rule violation) (2 Replies)
Discussion started by: smohan62
2 Replies

9. Shell Programming and Scripting

sed not working on AIX in ksh shell!

Hi All, I have this script which doesn't work on AIX ksh shell.. # ! /usr/bin/ksh grep -irl "6000" /home/applmgr/xyz > file_list_port.log xargs sed -i 's/6000/6010/g' < file_list_port.log But this same script has worked perfectly on linux bash shell.. Could anyone please share... (4 Replies)
Discussion started by: a1_win
4 Replies

10. UNIX for Dummies Questions & Answers

Sed command not working

Hi, I have a test file as follows: 1G102119 ^ AA1179291 ^ 06oct2006 09:50:35^ 73.4^ 2^ 13^ 0^ 1493 1G102119 ^ AA1179291 ^ 06oct2006 09:49:45^ 73.4^ 2^ 13^ 0^ 1493 1G102119 ^ AA1179291 ^ 06oct2006 09:48:58^ 73.4^ 2^ 17^ 0^ 2 1G102119 ... (9 Replies)
Discussion started by: shashi_kiran_v
9 Replies
Login or Register to Ask a Question