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 06-24-2009, 05:57 PM   #1
amymarma
LQ Newbie
 
Registered: Jun 2009
Posts: 1

Rep: Reputation: 0
Script to copy information only after a certain sequence


What i'm trying to do is more or less grep through a file (iptraf log) and grab only the bytes used for each line. It's in the form of:

Date; udp; eth0; xxxx bytes; ; ; ;

Is there a quick/easy way to do this using just VI (delete after "bytes"/sequence) or to grep for a certain variable sequence, perhaps in a bash script?

Thank you so much!
 
Old 06-24-2009, 06:06 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Hi,

Welcome to LQ!


I'm not sure I fully understand your request; the vim solution to what I
think you're asking for would be:
Code:
:%s/bytes;.+$/bytes/
With sed on the command line:
Code:
sed -r 's/(^.*bytes);.*/\1/' file

Cheers,
Tink
 
Old 06-24-2009, 06:10 PM   #3
Slim_Pikins
LQ Newbie
 
Registered: Jul 2004
Location: Manchester UK
Posts: 21

Rep: Reputation: 15
Sed would be the way Id go, and it can be used within vi

http://www.grymoire.com/Unix/Sed.html
 
Old 06-24-2009, 08:20 PM   #4
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
i see your delimiter is ";", then just use awk, simpler than constructing regex
Code:
awk -F";" '{print $4}' file
 
  


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 ssh in two machine one after another (in sequence) using shell script kushkothari Linux - Networking 21 10-21-2008 11:03 PM
script to ensure lines are in sequence docaia Linux - General 2 05-30-2008 06:10 AM
Need help adding a script to shutdown sequence trapix22 Linux - Newbie 1 12-29-2007 02:08 AM
man gives error information(iconv: illegal input sequence at position XX) haodongdong Linux - Software 1 05-04-2005 11:38 PM
Help to remove script from booting sequence sasha_baranov Linux - Newbie 1 11-18-2004 10:34 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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