Need help stripping statement from text file, ksh: sed awk?
This is my first time to this site, so go easy on me.
I'm writing a Korn Script that clears out the NO_HW entries from an ioscan. The script takes the output of the ioscan and places into a text file. The text file is reduced to only the lines with "NO_HW" on them. Example: Code:
ctl 54 0/3/0/0/0/0.0.21.11.0 sctl NO_HW DEVICE HP 260 SAS AJ940A Example: Code:
0/3/0/0/0/0.0.21.11.0 Code:
0/3/0/0/0/0.0.21.11.0 The command needs to be pretty versatile as the H/W path could be just about anything. I was thinking this could probably be done with sed or maybe awk but I'm not very proficient in those. Thanks. |
No need for anything as fancy as sed or awk.
cut -f3 file.txt This is assuming the fields are separated by tabs. If they're spaces you'll have to add '-d " "' and change the -f number to match the column you want. |
Quote:
Code:
[user@machine:~]:awk '{ print $3 }' < blah.txt Another approach would be to use sed to replace the spaces with commas, and then use cut: Code:
[user@machine:~]:sed -e 's/ */,/g' < blah.txt | cut -d ',' -f 3 |
Moin,
Quote:
Quote:
In the second example I'd prefer to let sed do the whole work. No need for cut: Code:
sed 's/[^ ]* *[^ ]* *\([^ ]*\).*/\1/' file.txt Code:
sed 's/[^ \t]*[ \t]*[^ \t]*[ \t]*\([^ \t]*\).*/\1/' file.txt |
Quote:
Quote:
Quote:
Quote:
|
Quote:
|
Moin,
*habit*, *not readable*, *makes me sick* - strange. I'd think, that efficiency in scripting should be a part of one's judgement too. Your awk solution is o.k., your sed / cut not, it's a waste of resources. Your *habit* to use redirect makes things more difficult to understand (unnecessary redirects and cat's are like an epidemic in my opinion!). I only wanted to show, how sed can be used to do the whole work in the second example - if one doesn't understand the line, he should be able to ask. It's a simple basic regular expression, nothing high sophisticated. Jan |
Quote:
Code:
[user@machine:~]:time awk '{ print $3 }' < long.txt >> /dev/null Quote:
Code:
[user@machine:~]:time sed -e 's/ */,/g' < long.txt | cut -d ',' -f 3 >> /dev/null Code:
[user@machine:~]:time cut -d ',' -f 3 < longc.txt >> /dev/null Quote:
Quote:
|
All times are GMT -5. The time now is 11:22 AM. |