Support LQ: Use code LQ3 and save $3 on Domain Registration
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-20-2008, 11:56 PM   #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-20-2008, 11:57 PM   #2
Registered: Oct 2007
Posts: 101

Original Poster
Rep: Reputation: 15

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

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

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

All times are GMT -5. The time now is 04:30 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