Review your favorite Linux distribution.
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 07-21-2008, 12:56 AM   #1
Registered: Oct 2007
Posts: 101

Rep: Reputation: 15
Exclamation how to cut first four digit of a string

Hi all

How to cut first four digit of a string?
if i have string 5657657767 then how to cut 5657 from string?
Old 07-21-2008, 12:57 AM   #2
Registered: Oct 2007
Posts: 101

Original Poster
Rep: Reputation: 15

echo "$string" | cut -c1-4
Old 07-21-2008, 07:32 PM   #3
Registered: Jun 2008
Posts: 101

Rep: Reputation: 15
For BASH scripts use:
echo ${stringZ:0:4} # 5657
Old 07-22-2008, 03:32 AM   #4
Valery Reznic
ELF Statifier author
Registered: Oct 2007
Posts: 676

Rep: Reputation: 137Reputation: 137
printf "%.4s" "$string"


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
15 digit long number Zagi Programming 3 07-14-2008 07:26 AM
C - how to check whether it's a digit sycamorex Programming 10 02-28-2008 06:37 PM
String manipulation (subst for cut) EmLS Programming 4 08-16-2007 01:53 AM
umask0000 what is the fourth digit for? cooljed Linux - Newbie 1 05-14-2006 02:45 PM
54 digit numbers Scratchit General 3 06-23-2004 10:24 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:05 AM.

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