Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have one file contains data as follows...

/tutordashboard/manageTutorLogInStatus/?ua=TQ-AUTOCLOSE-REENTER&filterId=089089087087080&dt=1325757272
/tutordashboard/manageTutorLogInStatus/?ua=TQ-AUTOCLOSE-REENTER&filterId=089089087087080&dt=1873982869
/tutordashboard/manageTutorLogInStatus/?ua=TQ-BUTTON-DISABLED&sessionType=1&sessionId=4938718&filterId=97462&dt=1354822214604
/tutordashboard/manageTutorLogInStatus/?ua=TQ-BUTTON-DISABLED&sessionType=1&sessionId=4951063&filterId=95997&dt=1354807593071
/tutordashboard/manageTutorLogInStatus/?ua=TQ-BUTTON-DISABLED&sessionType=2&sessionId=4957338&filterId=99353&dt=1354752909284

How can I get the output that prints till 3rd occurrence of "/" in each line?

share|improve this question

migrated from stackoverflow.com Dec 9 '12 at 16:22

This question came from our site for professional and enthusiast programmers.

3  
Anything that you have tried ? –  GajananH Dec 7 '12 at 8:31
    
If your input is representative, it would probably be better to instead print everything up to the first ?, and awk '{print $1}' FS=? works nicely. –  William Pursell Dec 7 '12 at 16:38
add comment

3 Answers 3

up vote 1 down vote accepted
awk -F/ 'BEGIN{OFS="/";}{print $1,$2,$3}' your_file
share|improve this answer
    
Thank you sarathi. –  Lingaraj Dec 7 '12 at 10:02
add comment

It's as simple as this: cut -d'/' -f1,4 <file

Example:

$ echo /foo/bar/baz/extra | cut -d'/' -f1-4
/foo/bar/baz
share|improve this answer
add comment
sed 's_\(/.*/.*\)/.*_\1_' your-file.txt

This is an example:

>sed 's_\(/.*/.*\)/.*_\1_' your-file.txt
/tutordashboard/manageTutorLogInStatus
/tutordashboard/manageTutorLogInStatus
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.