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 > Shell Programming and Scripting
.
google unix.com



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
To remove new line character shihabvk UNIX for Advanced & Expert Users 7 06-18-2009 07:44 AM
Can I read a file character by character? murtaza Shell Programming and Scripting 4 04-27-2009 05:51 AM
read a variable character by character, substitute characters with something else vipervenom25 UNIX for Dummies Questions & Answers 2 06-06-2008 03:18 PM
Can i read a file character by character karnan Shell Programming and Scripting 6 05-19-2008 02:22 AM
How to remove extraneous character vsmurali UNIX for Dummies Questions & Answers 7 03-18-2008 12:57 PM

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

Join Date: Feb 2008
Posts: 2
grep from filename.txt can't get the whole line!

Hi,

I've made a script to grep a file

Code:
for i in `cat filename.txt`
do
    strings ./binfile | grep "$i" 2>&1 > /dev/null
done
this works fine as long as in filename.txt i don't have any entries with spaces. But in my case i want to grep something with spaces like "lala tata"
and the above script greps for lala and then with tata.

When I use while read i have the same problem.
any ideas anyone??

thanks,
papasj

Last edited by papasj; 02-24-2008 at 11:13 AM.. Reason: trying to edit the title without luck
  #2 (permalink)  
Old 02-24-2008
robotronic's Avatar
robotronic robotronic is offline Forum Advisor  
Can I play with madness?
  
 

Join Date: Apr 2002
Location: Italy
Posts: 370
You have to set IFS to a newline character before executing your loop:

Code:
IFS="
"
for ...; do ...; done
Or, for a nicer single line version:
Code:
IFS=$'\n'
for ...; do ...; done

Last edited by robotronic; 02-24-2008 at 11:34 AM..
  #3 (permalink)  
Old 02-24-2008
papasj papasj is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 2
thanks

thanks, it works fine after the IFS
  #4 (permalink)  
Old 05-25-2009
vsigal vsigal is offline
Registered User
  
 

Join Date: May 2009
Posts: 1
also " tr " could delete END OF THE LINE , try

echo abcd | tr -d '\n'
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 02:03 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