![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| searching and storing unknown number of lines based on the string with a condition | swamymns | Shell Programming and Scripting | 7 | 05-12-2008 10:02 PM |
| how to seperate space in a string | kittusri9 | Shell Programming and Scripting | 5 | 05-08-2008 03:43 AM |
| sed - searching for string and storing in variable | melias | Shell Programming and Scripting | 4 | 04-12-2008 11:57 AM |
| Remove unregconized space from a string | Ricole | UNIX for Dummies Questions & Answers | 3 | 02-29-2008 01:35 AM |
| Storing space delimited line in var with loop? | eltinator | Shell Programming and Scripting | 2 | 08-23-2007 10:09 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
Storing string with space
Hi all
I am trying this simple command: a="abc abc" echo $a output is: abc abc But expected output shoould be :abc abc i.e spaces in real string are geting truncated to one space everytime. Plz Help. |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Wrap $a within double quotes i.e. "$a"
|
|
#3
|
|||
|
|||
|
Not working in script!
cat my_file | while read line
do last=`echo $line | cut -c 3-` echo "$last" done my_file: 1US8738297897918[space][space][space]0[space][space]0[space][space]0 1US8738297897918[space][space][space]0[space][space]0[space][space]0 1US8738297897918[space][space][space]0[space][space]0[space][space]0 Expected output: 8738297897918[space][space][space]0[space][space]0[space][space]0 8738297897918[space][space][space]0[space][space]0[space][space]0 8738297897918[space][space][space]0[space][space]0[space][space]0 Current Output: 8738297897918[space]0[space]0[space]0 8738297897918[space]0[space]0[space]0 8738297897918[space]0[space]0[space]0 Plz Help ! |
|
#4
|
||||
|
||||
|
The read command removes leading and traling Input Field Separators.
The echo command doesn't preserve multiple IFS between argument strings. Code:
while IFS= read line do last=`echo "$line" | cut -c 3-` echo "$last" done <my_file |
|
#5
|
|||
|
|||
|
Thankssssssssssssss
It worked !
|
|||
| Google The UNIX and Linux Forums |