![]() |
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 |
| replacing multiple lines with single line | siba.s.nayak | Shell Programming and Scripting | 3 | 05-28-2008 02:43 AM |
| How to compare null and space using single if condition | jayakumarrt | UNIX for Dummies Questions & Answers | 3 | 05-16-2008 05:13 AM |
| Replacing URL in a file with space | dsrookie | UNIX for Dummies Questions & Answers | 5 | 02-29-2008 04:58 AM |
| Consecutive spaces within input being converted to single space | NinersFan | Shell Programming and Scripting | 4 | 09-04-2007 08:59 AM |
| Replacing a single quote | rjsha1 | Shell Programming and Scripting | 3 | 12-23-2005 10:55 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
replacing single space in argument
I want to write a script which will check the arguments and if there is a single space(if 2 more more space in a row , then do not touch), replace it with _ and then gather the argument
so, program will be ran Code:
./programname hi hello hi usa now hello hello $1 = hi $2 = hello_hi $3 = usa $4 = now $5 = hello_hello It's rather diffuclt for me since I am not sure even if I got rid of space and replace it with _, not sure how to assign back to correct positional parameters.. Last edited by reborg; 04-24-2007 at 01:54 PM.. |
|
|||||
|
Quote:
|
|
||||
|
thanks guys.. but I am writing this script so that end user can be as lazy as possible(since they are copying from somewhere and pasting it as arguments).
I thought maybe I can do it as put the whole argument as array.. and then after doing the replacing( " " to _ ) and then assign it back to $1,$2 .... ? is this not possible in shell script? so, my logic would be, ./scriptname whatever whatever1 whate ever2 whate ver 2006 so, script would see it as @arrayname = $* # or possibly value = $1,$2,$3,$4,$5,$6 <--i would insert extra just in case and then possibly break it out using sed and awk.. but not sure how to assign it back... newvalue = |
|
|||||
|
Quote:
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|