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-06-2010, 11:52 AM   #1
haryo_linux
LQ Newbie
 
Registered: Nov 2008
Location: In a most peace place in the world
Distribution: OPEN SUSE
Posts: 8

Rep: Reputation: 0
Unhappy cut only 2nd line and 2 cahracter


hey every master.. i have a trouble here to cut a file

cut -c1-2 /etc/hasil.log
THE RESULT IS :
PI
64
64
64
64

--
4

==========================================================

THE VALUE OF /etc/hasil.log is:
PING 192.168.2.2 (192.168.2.2) 56(84) bytes of data.
64 bytes from 192.168.2.2: icmp_seq=1 ttl=64 time=0.045 ms
64 bytes from 192.168.2.2: icmp_seq=2 ttl=64 time=0.057 ms
64 bytes from 192.168.2.2: icmp_seq=3 ttl=64 time=0.055 ms
64 bytes from 192.168.2.2: icmp_seq=4 ttl=64 time=0.055 ms

--- 192.168.2.2 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 2999ms
rtt min/avg/max/mdev = 0.045/0.053/0.057/0.004 ms

===========================================================
i want RESULT is:
64

help me please
 
Old 04-06-2010, 12:01 PM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by haryo_linux View Post
hey every master.. i have a trouble here to cut a file

cut -c1-2 /etc/hasil.log
THE RESULT IS :
PI
64
64
64
64

--
4

==========================================================

THE VALUE OF /etc/hasil.log is:
PING 192.168.2.2 (192.168.2.2) 56(84) bytes of data.
64 bytes from 192.168.2.2: icmp_seq=1 ttl=64 time=0.045 ms
64 bytes from 192.168.2.2: icmp_seq=2 ttl=64 time=0.057 ms
64 bytes from 192.168.2.2: icmp_seq=3 ttl=64 time=0.055 ms
64 bytes from 192.168.2.2: icmp_seq=4 ttl=64 time=0.055 ms

--- 192.168.2.2 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 2999ms
rtt min/avg/max/mdev = 0.045/0.053/0.057/0.004 ms

===========================================================
i want RESULT is:
64

help me please
Start from

man head
man tail
.
 
Old 04-06-2010, 12:04 PM   #3
haryo_linux
LQ Newbie
 
Registered: Nov 2008
Location: In a most peace place in the world
Distribution: OPEN SUSE
Posts: 8

Original Poster
Rep: Reputation: 0
cut only 2nd line and 2 cahracter

hey every master.. i have a trouble here to cut a file

cut -c1-2 /etc/hasil.log
THE RESULT IS :
PI
64
64
64
64

--
4

==========================================================

THE VALUE OF /etc/hasil.log is:
PING 192.168.2.2 (192.168.2.2) 56(84) bytes of data.
64 bytes from 192.168.2.2: icmp_seq=1 ttl=64 time=0.045 ms
64 bytes from 192.168.2.2: icmp_seq=2 ttl=64 time=0.057 ms
64 bytes from 192.168.2.2: icmp_seq=3 ttl=64 time=0.055 ms
64 bytes from 192.168.2.2: icmp_seq=4 ttl=64 time=0.055 ms

--- 192.168.2.2 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 2999ms
rtt min/avg/max/mdev = 0.045/0.053/0.057/0.004 ms

===========================================================
i want RESULT is:
64

help me please
 
Old 04-06-2010, 12:28 PM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,935

Rep: Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692
Quote:
Originally Posted by haryo_linux View Post
hey every master.. i have a trouble here to cut a file

cut -c1-2 /etc/hasil.log
THE RESULT IS :
PI
64
64
64
64

--
4

==========================================================

THE VALUE OF /etc/hasil.log is:
PING 192.168.2.2 (192.168.2.2) 56(84) bytes of data.
64 bytes from 192.168.2.2: icmp_seq=1 ttl=64 time=0.045 ms
64 bytes from 192.168.2.2: icmp_seq=2 ttl=64 time=0.057 ms
64 bytes from 192.168.2.2: icmp_seq=3 ttl=64 time=0.055 ms
64 bytes from 192.168.2.2: icmp_seq=4 ttl=64 time=0.055 ms

--- 192.168.2.2 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 2999ms
rtt min/avg/max/mdev = 0.045/0.053/0.057/0.004 ms

===========================================================
i want RESULT is:
64

help me please
Try to write clearly...you're hard to understand.

First, I'd start by grep'ing the lines of the input log, to omit the fluff, like the "pi" etc.. Look for "icmp" in this case. That'll leave you with just the lines for the pings. Look at the man page for the uniq command, which should do what you want.
 
Old 04-06-2010, 12:30 PM   #5
devnull10
Member
 
Registered: Jan 2010
Location: Lancashire
Distribution: Slackware Stable
Posts: 548

Rep: Reputation: 116Reputation: 116
Well, one way would be to do this:

Code:
grep 'bytes from' hasil.log | cut -c1-2 | uniq
That of course assumes that the reply is always 64 bytes!

[edit]

^^ haha, someone beat me to it!
 
Old 04-06-2010, 12:35 PM   #6
Mr-Bisquit
Member
 
Registered: Feb 2009
Distribution: FreeBSD, OpenBSD, NetBSD, Debian, Fedora
Posts: 770
Blog Entries: 52

Rep: Reputation: 68
Keep the ping log as it is for future references.
 
Old 04-06-2010, 12:41 PM   #7
Fingers of Fudge
LQ Newbie
 
Registered: Aug 2007
Distribution: Slackware 13.0
Posts: 14

Rep: Reputation: 1
something like:

head -n 3 filename|tail -n 1|head -c 2

maybe??

E2A: can't figure how to get it into a file though using >

E2A: have now :-) yay!! I like Linux :-)

(head -n 3 filename|tail -n 1|head -c 2)>newfile

Last edited by Fingers of Fudge; 04-06-2010 at 12:48 PM.
 
Old 04-06-2010, 12:49 PM   #8
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
(not tested)
Code:
sed -n '2s/ .*//p' filename > newfilename
 
Old 04-06-2010, 12:53 PM   #9
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Please do not post duplicate threads.

since both had replies, I haved merged them.
 
Old 04-06-2010, 12:54 PM   #10
nonamenobody
Member
 
Registered: Oct 2002
Posts: 138

Rep: Reputation: 22
Code:
cut -c1-2 /etc/hasil.log | tail -n +2 |head -1
Of course it does kind of assume that the size will always be two characters or less. It may be better to use cut -f 1 -d ' ' /etc/hasil.log

Last edited by nonamenobody; 04-06-2010 at 01:04 PM. Reason: Edit: better option
 
Old 04-06-2010, 02:11 PM   #11
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
And for good measure an awk variant:
Code:
awk 'NR==2{print $1}' /etc/hasil.log
That said: having a log in /etc is a VERY STUPID idea.


Cheers,
Tink
 
  


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 and paste from command line dulli1 Linux - Newbie 9 10-12-2010 10:31 PM
Using Perl, how do I chomp every 2nd line? hawk__0 Programming 26 02-08-2010 01:57 PM
help with cut command using find. Cut last 8 characters leaving the rest ncsuapex Programming 4 09-16-2009 09:55 PM
Using cut to extract only last item in line? devnulljp Linux - Software 2 08-30-2009 06:58 PM
Cut(command) line by line leventis Programming 4 09-24-2006 07:51 PM


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