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
Linux Shell Question: how to print the shell script name ? meili100 UNIX for Dummies Questions & Answers 3 07-01-2008 02:55 PM
Urgent: selecting unique specific content of a file using shell script jisha Shell Programming and Scripting 2 01-08-2008 08:45 AM
shell script question tselvanin Shell Programming and Scripting 2 08-28-2007 10:53 PM
Shell script to check the unique numbers in huge data namishtiwari Shell Programming and Scripting 7 08-10-2007 10:38 AM
Problem with shell script...ORA-00904:invalid identifier bhagat.singh-j Shell Programming and Scripting 12 11-13-2006 10:33 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 07-22-2008
grahambo2005 grahambo2005 is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 15
Shell Script Unique Identifier Question

i All

I have scripting question.
I have a file "out.txt"

which is generated by another script

the file contains the following
Code:
my_identifier8859574

logout
The number is generated in the script and I have put the my_identifier bit in front of it as a unique identifier

I now have another script which uses this file, It needs the number Only that comes after my_identifier

I havn't a breeze how to do this.
I assume i need to use awk

something like

VALUE=cat out.txt | grep my_identifier | awk .....

any suggestions?
Cheers
Graham
  #2 (permalink)  
Old 07-22-2008
radoulov's Avatar
radoulov radoulov is online now Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,879
Is my_identifier always the first line or it could be anywhere in out.txt?

If 1:

Code:
id=$(read<out.txt;printf "%s" "${REPLY#my_identifier}")

else:

Code:
id="$(fgrep my_identifier out.txt)" id="${id#my_identifier}"

Last edited by radoulov; 07-22-2008 at 07:31 AM..
  #3 (permalink)  
Old 07-22-2008
grahambo2005 grahambo2005 is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 15
thank you kindly

this works perfectly
  #4 (permalink)  
Old 07-22-2008
grahambo2005 grahambo2005 is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 15
Apologies for asking again

but I am now having an issue with TR

I want to make double sure that the value of id has no non-numerical characters in it.

Code:

if [ ($id | tr -d '[:digit:]') == '' ]
then
#let do the next bit
else
#email me
fi
my if syntax is not correct though

im getting the error
./test.sh[12]: Syntax error at line 12 : `(' is not expected.

any advice?
Cheers
Graham
  #5 (permalink)  
Old 07-22-2008
radoulov's Avatar
radoulov radoulov is online now Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,879
Use case:

Code:
case "$id" in
  "" | *[!0-9]* ) # email me ;;
              * ) # let do the next bit ;;
esac
  #6 (permalink)  
Old 07-22-2008
methyl methyl is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 1,175
if [ -z "`echo $id | tr -d [0-9]`" ]
then
echo "Valid"
else
echo "Invalid"
fi
  #7 (permalink)  
Old 07-22-2008
grahambo2005 grahambo2005 is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 15
thank you very much sir

Graham
Closed Thread

Bookmarks

Tags
manipulation, variable

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 04:31 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