The UNIX and Linux Forums  

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
Retreive content between specific lines ina file chennaitomcruis Shell Programming and Scripting 4 04-19-2008 11:18 AM
Compare two arrays in sh or compare two fields rijeshpp Shell Programming and Scripting 0 10-31-2007 02:47 AM
Retreive string between two chars danland Shell Programming and Scripting 25 06-25-2007 04:02 PM
Retreive process output nhatch UNIX for Advanced & Expert Users 2 10-16-2003 11:55 AM
Compare Syed_45 UNIX for Dummies Questions & Answers 2 08-20-2001 04:53 PM

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 03-07-2007
omahablues omahablues is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 1
Trying to retreive and compare value

Hi All,

I'm have a file test.txt that looks like this

1939399393
03094994949
948383


I have to check whether the first character in the first line is 1 or not. I have tried the following option but it seems to fail

head -1 test.txt | grep ^1

but it seems to display the entire first line without validating

Any suggestions.

Thanks
  #2 (permalink)  
Old 03-07-2007
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
Code:
sed -e "s/^\(.\).*/\1/g;q" | grep "1"
  #3 (permalink)  
Old 03-07-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Code:
if [[ -n $( sed -n "/^1/s/.*/1/p;q" file ) ]]
then
   echo "First line contain 1 as first char"
fi
  #4 (permalink)  
Old 03-09-2007
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,361
Arrow

Quote:
Originally Posted by omahablues
Hi All,

I'm have a file test.txt that looks like this

1939399393
03094994949
948383


I have to check whether the first character in the first line is 1 or not. I have tried the following option but it seems to fail

head -1 test.txt | grep ^1

but it seems to display the entire first line without validating
You don't need any external commands to do that:

Code:
read line < text.txt
case $line in
   1*) echo "First character is 1" ;;
   *) echo "First character is not 1" ;;
esac
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 03:06 PM.


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