LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 04-07-2005, 10:10 AM   #1
p0tw0r
LQ Newbie
 
Registered: Apr 2005
Posts: 8

Rep: Reputation: 0
Print a part of variable/string


I would like to echo some specific digits from a more complex variable.
In windows i used:

echo %var1%
result - my_var

echo %var1:~4,2%
result - ar

How do I do it in bash?
 
Old 04-07-2005, 02:49 PM   #2
verzonnen
Member
 
Registered: Aug 2003
Posts: 31

Rep: Reputation: 15
you can use various tools like "cut" "awk" "perl" "sed" or even "expr" I have never tried to do the same in bash, anyway here is an example using cut

echo $VAR | cut -f1-4


Have a look at the man page for cut (man cut) for the correct syntax
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple bash script help, grabbing part of a string colabus Linux - Newbie 3 04-25-2005 09:42 AM
Getting part of variable p0tw0r Programming 3 04-11-2005 02:25 AM
unsetting a part of ENV variable praveenv Linux - Newbie 3 08-28-2004 09:36 AM
variable to string x2000koh Programming 4 07-30-2003 02:23 AM
Getting a variable name based on a string. jtshaw Programming 7 10-08-2002 02:06 PM


All times are GMT -5. The time now is 11:29 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration