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 a newbie in Linux scripting, especially for using sed and awk commands. For now I'm trying to filter a really big log file and wondering if there are any alternatives for my commands? or some optimizing? here is the code:

#!/bin/bash
nice -20 sed '/./{H;$!d;};x;/37455299339/!d' 1.txt > /tmp/new.txt
nice -20 sed -n '/Acct-Status-Type/,/NAS-Identifier/p' /tmp/new.txt > /tmp/new_1.txt
rm /tmp/new.txt
nice -20 sed '/Acct-Status-Type/{x;p;x;}' /tmp/new_1.txt > /tmp/new_2.txt
rm /tmp/new_1.txt
nice -20 less /tmp/new_2.txt | grep -A1 -B1 37455299339 | grep -A1 -B1 User-Name > new_3.txt
share|improve this question
    
You can try sed -i –  Bernhard Apr 12 '13 at 6:53
    
sed -i for which command? for all? –  user37033 Apr 12 '13 at 7:28
    
Yep, it updates the files in place, so you can get rid of the > and rm parts. –  Bernhard Apr 12 '13 at 7:58
2  
Rather than providing the sed commands, you should explain the problem you're actually trying to solve. –  frostschutz Apr 12 '13 at 11:02
1  
@user37033 Whith {H;$!d;}, you're storing whole input file in ram. In actual state of knowledge, we could'not help you. Give us some lines of input as sample and explain what's your goal. –  F. Hauri Jun 16 '13 at 7:58

1 Answer 1

As first step, I would remove all temporary files and use pipe instead: from first sed you may pipe stdout to second one and then to third one. Then, your less command is useless: just pipe again from the third sed to grep.

Using pipe you will have many benefits: first you will not waste your disk space, second, you will not wait for all these disk I/O.

For better finding a solution, you should tell us what is currently blocking you: is it one of the sed commands? Which one?

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.