Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 04-07-2005, 10:10 AM   #1
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
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


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 > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:24 PM.

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