Sed Newbie Question


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Sed Newbie Question
# 15  
Old 05-26-2011
coud you post the output of

Code:
od -bc tss.txt

# 16  
Old 05-26-2011
I think it's a problematic txt that i have to work. Your command works great for echo but when i try it with the file tyhat i have to work does strange things giving incorrect outpput

Because it's a big file i'm posting a part of the command output you asked
Code:
             \0      \0      \0      \0      \0      \0      \0      \0
12174400 174 000 040 000 174 000 060 000 060 000 060 000 060 000 060 000
          |  \0      \0   |  \0   0  \0   0  \0   0  \0   0  \0   0  \0
12174420 174 000 040 000 174 000 061 000 060 000 060 000 174 000 015 000
          |  \0      \0   |  \0   1  \0   0  \0   0  \0   |  \0  \r  \0
12174440 012 000 062 000 174 000 065 000 060 000 064 000 060 000 174 000
         \n  \0   2  \0   |  \0   5  \0   0  \0   4  \0   0  \0   |  \0
12174460 061 000 062 000 062 000 062 000 063 000 063 000 067 000 174 000
          1  \0   2  \0   2  \0   2  \0   3  \0   3  \0   7  \0   |  \0
12174500 060 000 174 000 060 000 071 000 057 000 060 000 065 000 057 000
          0  \0   |  \0   0  \0   9  \0   /  \0   0  \0   5  \0   /  \0
12174520 062 000 060 000 061 000 061 000 040 000 061 000 062 000 072 000
          2  \0   0  \0   1  \0   1  \0      \0   1  \0   2  \0   :  \0
12174540 060 000 060 000 174 000 060 000 071 000 057 000 061 000 061 000
          0  \0   0  \0   |  \0   0  \0   9  \0   /  \0   1  \0   1  \0
12174560 057 000 062 000 060 000 061 000 061 000 040 000 061 000 062 000
          /  \0   2  \0   0  \0   1  \0   1  \0      \0   1  \0   2  \0
12174600 072 000 060 000 060 000 174 000 060 000 061 000 057 000 060 000
          :  \0   0  \0   0  \0   |  \0   0  \0   1  \0   /  \0   0  \0
12174620 065 000 057 000 062 000 060 000 061 000 061 000 040 000 061 000
          5  \0   /  \0   2  \0   0  \0   1  \0   1  \0      \0   1  \0
12174640 062 000 072 000 060 000 060 000 174 000 040 000 174 000 067 000
          2  \0   :  \0   0  \0   0  \0   |  \0      \0   |  \0   7  \0
12174660 061 000 064 000 071 000 063 000 063 000 071 000 174 000 231 003
          1  \0   4  \0   9  \0   3  \0   3  \0   9  \0   |  \0 231 003
12174700 222 003 227 003 061 000 062 000 065 000 063 000 040 000 040 000
        222 003 227 003   1  \0   2  \0   5  \0   3  \0      \0      \0
12174720 040 000 174 000 040 000 174 000 060 000 060 000 174 000 040 000
             \0   |  \0      \0   |  \0   0  \0   0  \0   |  \0      \0
12174740 174 000 040 000 225 003 240 003 231 003 222 003 221 003 244 003
          |  \0      \0 225 003     003 231 003 222 003 221 003   � 003
12174760 231 003 232 003 221 003 040 000 231 003 224 003 056 000 247 003
        231 003 232 003 221 003      \0 231 003 224 003   .  \0   § 003
12175000 241 003 227 003 243 003 225 003 251 003 243 003 040 000 040 000
          ‘ 003 227 003   £ 003 225 003   © 003   £ 003      \0      \0
12175020 040 000 040 000 040 000 040 000 040 000 040 000 040 000 040 000
             \0      \0      \0      \0      \0      \0      \0      \0
12175040 040 000 040 000 040 000 040 000 040 000 040 000 040 000 174 000
             \0      \0      \0      \0      \0      \0      \0   |  \0
12175060 040 000 174 000 060 000 060 000 174 000 040 000 174 000 123 000

If it doesn't help i'll cut a smaller one, just take a look and tell me what you think
# 17  
Old 05-26-2011
give a try to this :
Code:
sed "s/\([^[:digit:]]\):/\1./g" tst.txt | tr -d '\0' >tss.txt

# 18  
Old 05-26-2011
Nope this doesn't work either. It's really strange with echo works great, when i try to run it for the txt it changes all the 12:00 to 12.00 , and generally everything from : to dot

Thanks for trying
# 19  
Old 05-27-2011
Quote:
Originally Posted by ctsgnb
Code:
$ echo "12:00 but i want to change AD:FG with AD.FG" | sed 's/\([[:alpha:]]\):/\1./g'
12:00 but i want to change AD.FG with AD.FG

I have a doubt, if I give
Code:
sed 's/\([A-Za-z]\)*:/\1./g'

or
Code:
sed 's/\([[:alpha:]]*\):/\1./g'

the output changes the 12:00 to 12.00, even though it is numerals. So, how the pattern is considering 12:00 as character string or alpha?
# 20  
Old 05-27-2011
Code:
$ cat /usr/share/misc/ascii | sed 's/[^[:print:]]//g' | fold -w 1 | sort | uniq | paste -sd" " -
   ! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~
$ cat /usr/share/misc/ascii | sed 's/[^[:alnum:]]//g' | fold -w 1 | sort | uniq | paste -sd" " -
 0 1 2 3 4 5 6 7 8 9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z
$ cat /usr/share/misc/ascii | sed 's/[^[:alpha:]]//g' | fold -w 1 | sort | uniq | paste -sd" " -
 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z
$ cat /usr/share/misc/ascii | sed 's/[^[:rune:]]//g' | fold -w 1 | sort | uniq | paste -sd" " -
   ! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~
$ cat /usr/share/misc/ascii | sed 's/[^[:punct:]]//g' | fold -w 1 | sort | uniq | paste -sd" " -
 ! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _ ` { | } ~
$ cat /usr/share/misc/ascii | sed 's/[^[:digit:]]//g' | fold -w 1 | sort | uniq | paste -sd" " -
 0 1 2 3 4 5 6 7 8 9
$ cat /usr/share/misc/ascii | sed 's/[^[:graph:]]//g' | fold -w 1 | sort | uniq | paste -sd" " -
 ! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~
$

---------- Post updated at 10:12 AM ---------- Previous update was at 10:05 AM ----------

Code:
$ for i in graph rune print alnum alpha punct digit; do echo '[[:'$i':]]' ; sed 's/[^[:'$i':]]//g' /usr/share/misc/ascii | fold -w 1 | sort | uniq | paste -sd"\0" -; done
[[:graph:]]
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
[[:rune:]]
 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
[[:print:]]
 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
[[:alnum:]]
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
[[:alpha:]]
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
[[:punct:]]
!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
[[:digit:]]
0123456789

---------- Post updated at 10:20 AM ---------- Previous update was at 10:12 AM ----------

@ Royal brahim : remove the wildcard

Code:
[ctsgnb@shell ~]$ echo "12:00" | sed 's/\([[:alpha:]]*\):/\1./g'
12.00
[ctsgnb@shell ~]$ echo "12:00" | sed 's/\([[:alpha:]]\):/\1./g'
12:00
[ctsgnb@shell ~]$

---------- Post updated at 10:21 AM ---------- Previous update was at 10:20 AM ----------

... or add another square bracket :
Code:
[ctsgnb@shell ~]$ echo "12:00" | sed 's/\([[[:alpha:]]]*\):/\1./g'
12:00
[ctsgnb@shell ~]$

---------- Post updated at 10:24 AM ---------- Previous update was at 10:21 AM ----------

or just
Code:
[ctsgnb@shell ~]$ echo "12:00" | sed 's/\([:alpha:]\):/\1./g'
12:00

All of the above was tested on a FreeBSD plateform

---------- Post updated at 10:29 AM ---------- Previous update was at 10:24 AM ----------

... interesting behaviour :

Code:
[ctsgnb@shell ~]$ echo "12:00" | sed 's/\([:alpha:]*\):/\1./g'
12.00
[ctsgnb@shell ~]$ echo "12:00" | sed 's/\([[:alpha:]]*\):/\1./g'
12.00
[ctsgnb@shell ~]$ echo "12:00" | sed 's/\([[[:alpha:]]]*\):/\1./g'
12:00
[ctsgnb@shell ~]$

I have no idea why it behaves like this... does anybody have a clue ?
# 21  
Old 05-27-2011
Good question, the pattern is considered like this
Code:
|0|25/05/2011 12:00|25/11/2011 12:00| ΙΔ.Χ | #OΔ:ΕΥ| 100|

As you can see from the above example i have about 60.000 records like that. Every | separates a field. The first one is numeric( |0| ), then it's alphanumeric for the other fields
Is this helpful?

Thanks
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed newbie question

hi all: i am trying to use sed to separate hex bytes "363834574e292c20" to "36 38 34 57 4e 29 2c 20". i used the following script (googled) and i got "3 63 83 45 74 e2 92 c2 0". how could i modify the script to meet my needs? thanks (8 Replies)
Discussion started by: ipfreak
8 Replies

2. Shell Programming and Scripting

What does this do (newbie question)...

I was looking through some code online and came accross this... ls *.txt | grep text1 | cat file1 – file2 | `echo wc –l` I know what "ls|grep text1" does and I know a word count gets echoed but beyond that I am confused. Please use layman terms as much as possible as I am a newbie. (8 Replies)
Discussion started by: elohssa
8 Replies

3. UNIX for Dummies Questions & Answers

newbie question

Hi all, I am sure this is very simple but I cant quite get it. I am trying to search textfile1.txt for a string then take the results of the search and append the result to textfile3.txt So far I have used $ find file1.txt -exec grep "string i am looking for" '{}' \; -print this... (2 Replies)
Discussion started by: radgator
2 Replies

4. Shell Programming and Scripting

perl newbie . &&..programming newbie (question 2)

Hello everyone, I am having to do a lot of perl scripting these days and I am learning a lot. I have this problem I want to move files from a folder and all its sub folders to one parent folder, they are all .gz files.. there is folder1\folder2\*.gz and there are about 50 folders... (1 Reply)
Discussion started by: xytiz
1 Replies

5. UNIX for Dummies Questions & Answers

UNIX newbie NEWBIE question!

Hello everyone, Just started UNIX today! In our school we use solaris. I just want to know how do I setup Solaris 10 not the GUI one, the one where you have to type the commands like ECHO, ls, pwd, etc... I have windows xp and I also have vmware. I hope I am not missing anything! :p (4 Replies)
Discussion started by: Hanamachi
4 Replies

6. Shell Programming and Scripting

SED question: newbie here.

Hello... I wanted to figure out how to remove the 1st instance of a comma from a file.. 100+ line file ------------- 'test1' ,'dudes are cool' <-- remove comma from first instance of comma in file ,'cool dude' ,'bbbbbb' I tried everything from cat jigar|tr , >1.txt to cat jigar|sed... (2 Replies)
Discussion started by: jigarlakhani
2 Replies

7. UNIX for Dummies Questions & Answers

Newbie question?

What is the best way to learn UNIX on the web, with out buying books? any link would be much help. Thank you in advance, L (1 Reply)
Discussion started by: lsoria1
1 Replies

8. UNIX for Dummies Questions & Answers

newbie question

I am taking a db classes toward oracle 10g. I am taking unix as well . I need to know what is the best option for os . should I use linux fedora. or get a sun box and start learning from there. Thanks (6 Replies)
Discussion started by: xzyan
6 Replies

9. Shell Programming and Scripting

newbie question

hey all, I have repeatedly seen scripts containing the following syntax, grep "hello" $myfile >> $log 2>&1 can anyone explain exactly what "2>&1" mean? THANK YOU (4 Replies)
Discussion started by: mpang_
4 Replies

10. UNIX for Dummies Questions & Answers

Very new newbie question

sorry if im not asking inthe right spot but, how do you turn the beeping off every time you hit a key onthe keyboard. I tried the click -n but it told me it didnt recognize click any help would be greatly appreciated ( the beeping is not going over well in the surrounding cubicles) thank you... (4 Replies)
Discussion started by: Split100
4 Replies
Login or Register to Ask a Question