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
This script cut size of files "Lol" change string in files single Shell Programming and Scripting 4 11-30-2008 04:40 PM
script running with "ksh" dumping core but not with "sh" simhe02 HP-UX 9 11-04-2008 08:52 PM
search excat string in another string (grep "fails") bora99 UNIX for Dummies Questions & Answers 0 06-05-2008 06:41 AM
#!/bin/sh script fails at StringA | tr "[x]" "[y]" by_tg UNIX for Dummies Questions & Answers 3 02-22-2008 12:17 PM
Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" Lokesha UNIX for Dummies Questions & Answers 4 12-20-2007 01:52 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-05-2009
yabhi_22 yabhi_22 is offline
Registered User
  
 

Join Date: Oct 2008
Location: mumbai India
Posts: 10
"$variable" is not behaving as a string in my script

Hi All,
I am using the below while syntax for reading my file but its not working. Below is the line in my file
" 123 rteyu 566"
when I use below code the spaces are truncated for 1st variable
while read line
do
x=`echo "$line"|cut -c 1-8`
y=`echo "$line"|cut -c 9-15`
echo "$x"
echo "$y"
done < file

Ideally x should show " 1" and y should be "23 r"
But x is showing value "123 r".
The intial spacing is being trucated.
Can any one help me on this!!!!!!
  #2 (permalink)  
Old 02-05-2009
yabhi_22 yabhi_22 is offline
Registered User
  
 

Join Date: Oct 2008
Location: mumbai India
Posts: 10
Forgot to mention I am using korn shell.
  #3 (permalink)  
Old 02-05-2009
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,859
You need to modify the current IFS to achieve this,
try:

Code:
while IFS= read ...
  #4 (permalink)  
Old 02-06-2009
yabhi_22 yabhi_22 is offline
Registered User
  
 

Join Date: Oct 2008
Location: mumbai India
Posts: 10
Hey Thanks!
I changed the IFS to : and wrote the same while loop I was using.
Now the loop's working fine.
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 01:49 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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