![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
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 |
| how to append spaces(say 10 spaces) at the end of each line based on the length of th | prathima | UNIX for Dummies Questions & Answers | 17 | 01-28-2009 04:10 PM |
| Replacing leading zeros with leading spaces | deepakwins | UNIX for Dummies Questions & Answers | 5 | 06-18-2008 03:06 AM |
| replacing tabs to spaces from files | rishir | Shell Programming and Scripting | 6 | 12-15-2005 01:12 PM |
| finding & replacing blank rows/spaces in a file | Gerry405 | SUN Solaris | 2 | 07-21-2005 05:49 AM |
| Strip leading and trailing spaces only in a shell variable with embedded spaces | jerardfjay | Shell Programming and Scripting | 6 | 03-07-2005 02:24 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
need help in replacing spaces in a file
hi all
this is the part i am facing a problem eg data: filename : tr1 + T 40 this is a sample record in that file ... the value of T can be anything, but will be a single character. i need to cut from field two, and i am using this command cut -d " " -f2 tr1 >tr3 and the o/p is 40 if i try to replace the spaces between + and T using sed sed 's/\t/ /g' tr1>tr3 o/p : + T 40 it is not a tab..... so i tried to replace it like this ..... tr -s " " "" tr1>tr3 o/p : + T 40 ... it is not reading it as a space .... more wierd is this .. i tried to cut the file column wise ... > cut -c 1 test1 + > cut -c 2 test1 > cut -c 3 test1 T i copied the record and pasted it in a notepad and i found that it is tab. i cannot find out whether it is a space or a tab .... can any one give me a solution ... i am trying to do the following but not sure how to do ... i want to replace everything that is there before tht "T" or "F" with a space... is it possible...? |
|
||||
|
First of all, i am sorry to say that i didnt understood ur problem , but whatever i understood
cat test + T 40 cat test | tr -d " " | sed -e 's/^./ /g;s/\( \)\(.\)/\1\2 /' T 40 Last edited by Bijayant Kumar; 10-04-2008 at 02:15 AM.. |
|
||||
|
Quote:
This code should be like this cat test |sed -e 's/^.*+//g'|tr -d "\t" It will take care any number of "tabs" or "spaces" present before the "+" sign. No matter its a "space or tabs". It will give the desired output. First give this a try at least ![]() |
|
||||
|
Aside: Both of your commands to remove spaces or tabs do not work. This is why you were misled.
Try: To remove spaces: tr -d " " To remove tabs: TAB=`echo "\0011"` tr -d "${TAB}" Notwithstanding "joeyg" good advice. To get a feel for whether white space is spaces or tabs you can substitute them both to make them visible. TAB=`echo "\0011"` cat filename|sed -e "s/${TAB}/TAB/g"|sed -e "s/ /SPACE/g"|pg (Shell purists may cringe at this inefficient pipeline but it is only an example). In your case the original problem is with using "cut" which requires a fixed delimiter. If your use "awk" to get the second field it won't matter whether its a space or a tab. cat filename|awk '{print $2}' |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|