LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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 09-25-2008, 10:37 AM   #1
tikit
Member
 
Registered: Feb 2008
Posts: 84

Rep: Reputation: 16
cut command - how to find separator?


Hi all,

I want to use cut to parse syslog messages from Cisco devices

the message seams like this:
Code:
 1 10.28.63.12 49948: Sep 25 07:36:16: %LINK-3-UPDOWN: Interface GigabitEthernet0/7, changed state to up
I used this to get IP address and mnemonic

Code:
cat syslog | grep -f 2,7 -d ' '
but it displays nothing. I think, there is a problem with the separator character, because if I cut and paste the line to a different file, it works.
Is there a way how to get the separator?
 
Old 09-25-2008, 10:58 AM   #2
mamtasahai1
Member
 
Registered: Jan 2007
Location: India
Distribution: RHEL 5, Fedora 9, Solaris, FreeBSD
Posts: 52

Rep: Reputation: 15
Try this:
cut -d" " -f 2,7 syslog
 
Old 09-25-2008, 11:03 AM   #3
CRC123
Member
 
Registered: Aug 2008
Distribution: opensuse, RHEL
Posts: 374
Blog Entries: 1

Rep: Reputation: 32
First of all, use the 'cut' command not grep (but I suspect this was only a typo). Also, try without -d option. syslog may use tabs between fields and that's the default for cut
 
Old 09-25-2008, 11:30 AM   #4
tikit
Member
 
Registered: Feb 2008
Posts: 84

Original Poster
Rep: Reputation: 16
If I use
Code:
cut -d" " -f 2,7 syslog
nothing is displayed
If I use
Code:
cut -f 2,7 syslog
the whole line is displayed not only the selected columns. There must be a different separator. It is really strange. It works when I copy and paste it to another file.
Thanks for help
 
Old 09-25-2008, 11:40 AM   #5
CRC123
Member
 
Registered: Aug 2008
Distribution: opensuse, RHEL
Posts: 374
Blog Entries: 1

Rep: Reputation: 32
Thats weird, what OS you on?
 
Old 09-25-2008, 12:20 PM   #6
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 234Reputation: 234Reputation: 234
Quote:
Originally Posted by tikit View Post
If I use
Code:
cut -d" " -f 2,7 syslog
nothing is displayed
If I use
Code:
cut -f 2,7 syslog
the whole line is displayed not only the selected columns. There must be a different separator. It is really strange. It works when I copy and paste it to another file.
Thanks for help
After the -f don't put a space, I've seen issues when a space is added, not sure why, putting space works fine on my Fedora 8 system I'm currently on but try without.

Code:
cut -d" " -f2,7 syslog
 
Old 09-25-2008, 12:23 PM   #7
tikit
Member
 
Registered: Feb 2008
Posts: 84

Original Poster
Rep: Reputation: 16
Hi,

problem is solved. the log file contained space characters at the beginning of the line. There was an error in the script that preprocessed the log file.
 
Old 09-25-2008, 12:28 PM   #8
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 234Reputation: 234Reputation: 234
Quote:
Originally Posted by tikit View Post
Hi,

problem is solved. the log file contained space characters at the beginning of the line. There was an error in the script that preprocessed the log file.
That'll do it as well.
 
  


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
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
Bash command separator/arguments separator reverse Programming 11 12-02-2007 10:21 PM
Cut Command Help!! fooforon Programming 2 02-05-2004 11:09 AM
cut / awk command?? Sammy2ooo Linux - Newbie 1 05-27-2003 06:46 PM


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