LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 07-21-2008, 12:56 AM   #1
kkpal
Member
 
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
kkpal
Member
 
Registered: Oct 2007
Posts: 101

Original Poster
Rep: Reputation: 15
Smile

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

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

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


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
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


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