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'm trying to print out all the lines up to the appearance of a particular song and 5 more songs with that. The problem i'm new to the shell what I have to fix in the bellow commands?

RANK  NAME                    BAND  YEAR   GENERE  DOMESTIC/INTERNATIONAL   
206:Reach Out, I'll Be There:The Four Tops:1978:Pop:3/2         
207:Bye Bye Love:The Everly Brothers:1950:Classic:3/2     
208:Gloria:Them:1965:Classic:1/1      
209:In My Room:The Beach Boys:1985:Classic:5/7  
210:96 Tears:? & the Mysterians:1964:Classic:20/15     
211:Caroline, No:The Beach Boys:1975:Classic:5/7   
212:1999:Prince:1958:Classic:5/7       
213:Your Cheatin' Heart:Hank Williams:1988:Soul:7/6 
awk '{print * "For What It's Worth"} ' songs            
awk '/For What It's Worth/, {print $1 $2}' songs
share|improve this question
    
Can you try explaining this a bit more, it's unclear what you're asking. –  slm Apr 19 at 0:05
    
@slm I want a command to print out all the lines up to "Caroline, No" and 5 songs after that. like print from the beginning up to song name "Caroline" and 5 more songs (lines) after that. –  Intermd11 Apr 19 at 0:07
1  
In general: If you ask something like that then you should always provide example input and example output. –  Hauke Laging Apr 19 at 0:13
    
@Intermd11 - Also since you're pretty new to our site if you notice under your Q there's a edit link. You can refine your Q as you get feedback from others or if you want to expand it so that it better illustrates your problem. The comment you left me for example could be adapted into the Q. –  slm Apr 19 at 0:15
    
@HaukeLaging Sure –  Intermd11 Apr 19 at 0:33

2 Answers 2

up vote 4 down vote accepted

Not sure what your attempted solution has to do with the problem you state; if your problem description is accurate the following should work

awk 'NR==1,/Caroline, No/{print;next};c++<5{print};' file
share|improve this answer
    
Probably easier to understand with c++<5 {print} (and adding the info that {print} is not necessary). –  Hauke Laging Apr 19 at 0:18
    
I appreciat it your help but what if I have a song named "For What It's Worth". probably that command will not work because the song name contain the symbol (It's). –  Intermd11 Apr 19 at 0:23
    
@Intermd11, awk "NR==1,/For What It's Worth/{print;next};c++<5{print}" file should take care of it –  1_CR Apr 19 at 0:25
    
@HaukeLaging, you are probably right, amended answer. I usually get upbraided on SO for being too verbose with awk but when it comes to newbies i see your point –  1_CR Apr 19 at 0:26
    
@1_CR that actually worked, thank you for your assistance. –  Intermd11 Apr 19 at 0:28
sed '/For What It.s Worth/{N;N;N;N;N;q}'
share|improve this answer

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.