LinuxQuestions.org
Help answer threads with 0 replies.
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 04-29-2013, 02:49 PM   #1
roopakl
Member
 
Registered: Sep 2011
Posts: 92

Rep: Reputation: Disabled
cut/grep command help


Hi All,
I got output as below from a command
Code:
192.168.0.251]
192.168.0.25]
192.168.2.3]
10.255.255.254]
Now I want that output to be as only
Code:
192.168.0.251
192.168.0.25
192.168.2.3
10.255.255.254
How to skip "]" and get only IPs. Thanks in advance for your kind reply.
 
Old 04-29-2013, 02:51 PM   #2
moody_mark
LQ Newbie
 
Registered: Jan 2010
Posts: 10

Rep: Reputation: 1
you could try

Code:
cut -d\] -f1 <filename>
 
1 members found this post helpful.
Old 04-29-2013, 02:53 PM   #3
Sigg3.net
Member
 
Registered: Mar 2008
Location: Oslo, Norway
Distribution: Slackware 14.1 64-bit, Ubuntu 15.10, Fedora 17, Ubuntu 12 LTS and Ubuntu server 10.04
Posts: 168

Rep: Reputation: 23
add this to your code:
Code:
| tr -d "]"
It will pipe the output of the grep command to the translate tool, which here deletes any hits of ].
 
1 members found this post helpful.
Old 04-29-2013, 02:59 PM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529
or with awk
Code:
| awk -F']' '{print $1}'
or pure shell:
Code:
| while read ITEM; do echo "${ITEM//]/}"; done
 
1 members found this post helpful.
Old 04-29-2013, 03:03 PM   #5
roopakl
Member
 
Registered: Sep 2011
Posts: 92

Original Poster
Rep: Reputation: Disabled
Hi Thank you both. You both saved my time.
Code:
| cut -d\] -f1
or
| tr -d "]"
The both commands worked as I had expected.
Thanks a lot.
 
Old 04-29-2013, 03:06 PM   #6
roopakl
Member
 
Registered: Sep 2011
Posts: 92

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by unSpawn View Post
or with awk
Code:
| awk -F']' '{print $1}'
or pure shell:
Code:
| while read ITEM; do echo "${ITEM//]/}"; done
Thank you, worked nicely.
 
  


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
Need help with the cut command..or should I be using the grep command? ProAm500 Linux - Newbie 15 05-01-2013 05:01 AM
[SOLVED] How to grep, cut, cat in a single command? dwarf007 Programming 6 04-27-2010 03:36 AM
How to use command grep,cut,awk to cut a data from a file? hocheetiong Linux - Newbie 7 09-11-2008 08:16 PM
grep and cut command tanveer Linux - General 3 09-05-2008 03:17 AM


All times are GMT -5. The time now is 06:18 AM.

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