LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 09-04-2008, 11:02 PM   #1
tanveer
Member
 
Registered: Feb 2004
Location: e@rth
Distribution: RHEL-3/4/5,Gloria,opensolaris
Posts: 489

Rep: Reputation: 37
grep and cut command


Hello,
I was writing a script to grep required informations from squid log and need some comments on the below scene. its just a sample file.

PHP Code:
[root@localhost ~]# cat test
fasdf kflfs  stream/flv
asdfd  asdfsdfsd
.flv
fadfs  sfdsfs
.flvtipu
adf  kasdfjklsdfj  
.flv?alsdslk=sfdds
abcd  efgh  abcflv

[root@localhost ~]# grep "\<flv\>" test
fasdf kflfs  stream/flv
asdfd  asdfsdfsd
.flv
.flv?alsdslk=sfdds

[root@localhost ~]
why does the below two lines didn't appear in grep output as both of them also consists 'flv'
Code:
fadfs  sfdsfs.flvtipu
abcd  efgh  abcflv
One more favor how to cut a portion of a sentence based on a character say if the URL is like

http://www.download.com/abc/winzip.exe?av=sdfs2343343

I want only the portion before '?' mark. With awk I can take the whole link from proxy log but how to omit the portion after ? mark in URL field.

Thanks in advance.
 
Old 09-04-2008, 11:49 PM   #2
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,225

Rep: Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021
1. why not just grep for flv ?
2. echo http://www.download.com/abc/winzip.e...dfs2343343|cut -d'?' -f1
 
Old 09-05-2008, 12:29 AM   #3
tanveer
Member
 
Registered: Feb 2004
Location: e@rth
Distribution: RHEL-3/4/5,Gloria,opensolaris
Posts: 489

Original Poster
Rep: Reputation: 37
No, I can't do that.

The proxy log is say like this
PHP Code:
1219921073.470   4731 10.10.X.XX TCP_MISS/200 252539 GET http://www.smartdraw.com/examples/content/Examples/SmartDraw/Gantt_Charts,_Project_Charts_&_Timelines/Gantt_Charts/sd8_Project_Schedule.exe DIRECT/63.241.25.134 application/octet-stream 
Now I am searching based on file extensions like .exe,.flv,etc so if I just grep exe then if any word contains that sequence will also come which won't serve my purpose.

Now I can awk the 7th field that is the URL.

But if the link is like this i.e., after .exe therer is a '?' mark which I dont want to store in database/file and just want upto .exe.

http://www.smartdraw.com/examples/co...343kdfd,asdfsd



thanks.
 
Old 09-05-2008, 02:17 AM   #4
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 59
perl -ane '$F[6] =~ s/\?.*$//; print "$F[6]\n"'
 
  


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP + bash: grep, cut or explode ???? :S ALInux Programming 3 12-13-2005 01:11 PM
cut , paste or grep ziox Programming 1 12-15-2004 10:51 PM
tcprobe+grep+cut Axion Programming 1 08-24-2004 05:27 AM
Cut Command Help!! fooforon Programming 2 02-05-2004 10:09 AM
cut / awk command?? Sammy2ooo Linux - Newbie 1 05-27-2003 05:46 PM


All times are GMT -5. The time now is 01:52 AM.

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