![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| converting a tabular format data to comma seperated data in KSH | Hemamalini | UNIX for Dummies Questions & Answers | 2 | 06-16-2008 05:37 AM |
| how to read the data from an excel sheet and use those data as variable in the unix c | Anne Grace | UNIX for Advanced & Expert Users | 1 | 03-03-2008 07:21 AM |
| how to verify that copied data to remote system is identical with local data. | ynilesh | Shell Programming and Scripting | 3 | 01-31-2008 08:55 AM |
| Howto capture data from rs232port andpull data into oracle database-9i automatically | boss | UNIX for Dummies Questions & Answers | 1 | 09-23-2007 03:35 AM |
| Using loop reading a file,retrieving data from data base. | Sonu4lov | Shell Programming and Scripting | 1 | 01-19-2007 03:38 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Cant get the data I want
Basically I have data that seems to have spaces or some other char that I can not see, please read below:
1/ When I run the command: "cat file | sed 's/[^a-zA-Z0-9+_:-@]//g' | sed 's|.*ex:Msg\(.*\)ex:Msg.*|\1|' " the extracted data within the ex:Msg tags which contains text with spaces is extracted correctly without any spaces which are taken out by the former sed command. 2/ When I change the former sed 's/[^a-zA-Z0-9+_:-@]//g' to include spaces sed 's/[^a-zA-Z0-9 +_:-@]//g' the whole data I send to the command is extracted, this includes data within the ex:Msg tags, this is not what I want. 3/ When I first replace the space with say a # by using the sed -e 's/ /#/g' before extracting the ex:Msg portion I still get the same result as 2 but the spaces are now # Hence, I am not sure if it is the spaces that is causing the problem, but when I remove them completely everything works, though I need the spaces within the text. Any ideas what I can do to resolve this problem |
|
||||
|
Try doing a cat -vet on the original file, it should show any hidden characters. Also file file should tell you if it is anything other than plain text. Failing that it is difficult to diagnose without a sample of the source data, I can't see any obvious problem with your second sed script... seems to work fine for me with or without spaces: Code:
$ echo "foo bar ex:MsgInteresting Text Here!ex:Msg blah yak" | sed 's/[^a-zA-Z0-9+_:-@]//g' | sed 's|.*ex:Msg\(.*\)ex:Msg.*|\1|' InterestingTextHere $ echo "foo bar ex:MsgInteresting Text Here!ex:Msg blah yak" | sed 's/[^a-zA-Z0-9 +_:-@]//g' | sed 's|.*ex:Msg\(.*\)ex:Msg.*|\1|' Interesting Text Here $ What operating system, version of sed, etc. are you using? |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|