The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
substring ?? varungupta Shell Programming and Scripting 7 10-01-2007 09:18 AM
substring panknil Shell Programming and Scripting 4 10-01-2007 08:12 AM
substring alla.kishore UNIX for Dummies Questions & Answers 8 01-09-2007 02:57 AM
swap space / paging space aaronh AIX 2 05-19-2004 10:06 AM
pageing space vs swap space VeroL UNIX for Dummies Questions & Answers 1 01-22-2004 11:54 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-22-2008
prassu prassu is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 6
Substring not working if more than 1 space

I have a string which is something like this..

abcd efghijkl

when I use this using substring() function 2 spaces are bein considered as one starngely.

Is there any thing I am doing wroing

the input file maintest has the string specified and the code is below


while read lines
do
echo $lines | awk '{print substr($0,4,3)}'

done < maintest

the output is
d e

where as it should be 'd ' d followed by 2 blank spaces.

Please suggest
thanks
  #2 (permalink)  
Old 08-22-2008
redoubtable redoubtable is offline
Registered User
  
 

Join Date: Aug 2008
Location: Portugal
Posts: 242
Your code works if there is more than one space. Maybe the problem is that you're testing with echo and if you do echo word1<space><space>word2 the output will be "word1<space>word2". If you want echo to output more than one space use ", echo "word1<space><space>word2".
  #3 (permalink)  
Old 08-22-2008
prassu prassu is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 6
perfect !!

just replaced

echo $line with echo "$line" | awk '{print substr($0,4,3)}'


Thanks a lot..


  #4 (permalink)  
Old 08-22-2008
redoubtable redoubtable is offline
Registered User
  
 

Join Date: Aug 2008
Location: Portugal
Posts: 242
No problem. That happened because despite how many spaces you type, the number of arguments is the same and echo only cares about arguments (which are then separated by a single space).

Code:
echo one        two
Those are two arguments "one" and "two".
Code:
echo "one      two"
That is one argument "one two".

Glad I could help.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 05:05 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0