I'm having troubles trying to extract the 2nd and 5th line from my file. It doesn't matter to me what tool is used: grep, sed, awk, perl, etc., I just need help. I have multiple files and the 2nd and 5th line change everyday with a new timestamp in all of them. I want to do something like this:
Thanks, all this is very useful. My problem now is that all these different commands are only extracting lines 2 and 5 from the 1st file. It apparently is ignoring the other files even though I'm specifying a wildcard: MOB.stats.04*
Here are three of the filenames:
Thanks for all your help so far.
Originally posted by aigles
Try something like this
# With sed
sed -n '2p;5p' input_file
# With awk
awk 'NR==1 || NR==5' input_file
# With awk, for multiple input files
awk 'FNR==1 || FNR==5' input_file1 input_file2 ...
awk 'FNR==1 || FNR==5' MOB.stats.04*