![]() |
|
|
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 |
| Korn: How to loop through a string character by character | shew01 | Shell Programming and Scripting | 10 | 12-02-2008 07:58 AM |
| Sed-Special character replacement | usshell | Shell Programming and Scripting | 3 | 05-22-2008 11:06 AM |
| KSH - Character Replacement | mixxamike | Shell Programming and Scripting | 2 | 09-24-2007 04:43 PM |
| Character replacement | piooooter | Shell Programming and Scripting | 2 | 09-06-2007 03:48 AM |
| Korn Shell Help Needed | stevefox | Shell Programming and Scripting | 5 | 12-05-2005 10:17 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
How do I replace a space " " character at a particular position in a line? e.g. I have a file below Code:
$ cat i2 111 002 A a 33 0011 B c 2222 003 C a I want all the 1st spaces to be replaced with forward slash "/" and the 3rd spaces to have 5 spaces to get the output below: Code:
111/002 AAA a 33/0011 BBB c 2222/003 CCC b I created a shell which would achieve this but I'm looking for a easier way. Code:
$ cat test.ksh #!/bin/ksh cut -d' ' -f1 < $1 > 1st_word cut -d' ' -f3 < $1 > 3rd_word while read line do sed -e "s/$line /$line\//g" $1 | grep $line done < 1st_word > tmp_ouput while read line do sed -e "s/$line /$line /g" tmp_ouput1 | grep $line done < 3rd_word Any help will be appreciated Steve |
|
||||
|
Try this.. Code:
sed -e 's/ /\//' -e 's/\(.* .*\)\( .*\)/\1 \2/' filename Output: Code:
cat temp 111 002 A a 33 0011 B c 2222 003 C a sed -e 's/ /\//' -e 's/\(.* .*\)\( .*\)/\1 \2/' temp 111/002 A a 33/0011 B c 2222/003 C a |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|