LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 02-20-2014, 03:01 PM   #1
maddyfreaks
Member
 
Registered: May 2011
Posts: 70

Rep: Reputation: 0
Question on Cut


Hi Team.

Got a question

I have variable AB.16.89

i need to change it to AB1689 not sure how to change it using cut (or) awk.

SYIN=AB.16.89

echo $SYSIN|cut -d '.' -f * ???
 
Old 02-20-2014, 03:11 PM   #2
metaschima
Senior Member
 
Registered: Dec 2013
Distribution: Slackware
Posts: 1,982

Rep: Reputation: 490Reputation: 490Reputation: 490Reputation: 490Reputation: 490
I would use tr or sed to simply delete the '.'s
 
1 members found this post helpful.
Old 02-20-2014, 03:13 PM   #3
Isaac Velando
LQ Newbie
 
Registered: Feb 2014
Location: Texas
Distribution: Arch, Ubuntu Server, CentOS
Posts: 29

Rep: Reputation: 21
If all you're trying to do is remove the periods then arguably the most appropriate tool (though as with most text manipulation tasks in bash not the only one) for the job is sed:
Code:
man sed
sed let's you use regular expressions to manipulate text in files or an output stream, so for instance:
Code:
echo $SYSIN | sed 's/\.//g'
The sed syntax used here has the form:
Code:
's(search and replace)/regex pattern to match/replacement/g(replace all matches, not just one)'
In the example I gave the period is escaped since otherwise periods match any character, and it replaces it with nothing (i.e. removes it).
 
Old 02-20-2014, 03:13 PM   #4
Habitual
LQ Addict
 
Registered: Jan 2011
Location: Youngstown, Ohio
Distribution: LM17.1/Xfce4.11.8
Posts: 7,186
Blog Entries: 10

Rep: Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981
Code:
echo AB.16.80 | sed 's/\.//g'
slow typer. Thanks Issac!
 
1 members found this post helpful.
Old 02-20-2014, 03:22 PM   #5
maddyfreaks
Member
 
Registered: May 2011
Posts: 70

Original Poster
Rep: Reputation: 0
thanks solved my proble
 
Old 02-20-2014, 04:51 PM   #6
metaschima
Senior Member
 
Registered: Dec 2013
Distribution: Slackware
Posts: 1,982

Rep: Reputation: 490Reputation: 490Reputation: 490Reputation: 490Reputation: 490
Here's the tr solution
Code:
echo AB.16.80 | tr -d '.'
 
Old 02-20-2014, 04:59 PM   #7
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Since the string is assigned to a variable, I suggest a simple parameter substitution:
Code:
SYSIN=${SYSIN//./}
 
Old 02-20-2014, 05:00 PM   #8
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
If you arw using bash, then use bash


Code:
MyVar=AB.16.80
MyVar=${MyVar//./}
For more infom do a search for
"Bash string manipulation"
 
  


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
cut command question tru64 Other *NIX 3 11-29-2009 03:49 AM
Keyboard Short-Cut Question Thanotos Linux - Newbie 8 02-09-2006 08:05 AM
cut question krock923 Programming 1 10-19-2005 05:03 PM
simple bash question about cut perfect_circle Programming 2 05-17-2005 12:25 PM


All times are GMT -5. The time now is 08:36 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration