LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to delete different column in a file? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-delete-different-column-in-a-file-516110/)

Tuku 01-04-2007 12:28 AM

how to delete different column in a file?
 
I am new to Linux. I have the foollowing information in a file and I have to delete the 2nd and third column. Please tell me how can I do it?

ft0.fm2.fail | 3Dh | ok | 29.2 | Predictive Failure Deasserted
ft1.fm0.fail | 3Eh | ok | 29.3 | Predictive Failure Deasserted
ft1.fm1.fail | 3Fh | ok | 29.4 | Predictive Failure Deasserted
ft1.fm2.fail | 40h | ok | 29.5 | Predictive Failure Deasserted
ft0.fm0.f0.speed | 41h | ok | 29.0 | 10000 RPM
ft0.fm1.f0.speed | 42h | ok | 29.1 | 9000 RPM
ft0.fm2.f0.speed | 43h | ok | 29.2 | 10000 RPM
ft1.fm0.f0.speed | 44h | ok | 29.3 | 11000 RPM
ft1.fm1.f0.speed | 45h | ok | 29.4 | 11000 RPM
ft1.fm2.f0.speed | 46h | ok | 29.5 | 10000 RPM
ft0.fm0.f1.speed | 47h | ok | 29.0 | 9000 RPM

thanks
-Tuku-

rnturn 01-04-2007 12:43 AM

Quote:

Originally Posted by Tuku
I am new to Linux. I have the foollowing information in a file and I have to delete the 2nd and third column. Please tell me how can I do it?

ft0.fm2.fail | 3Dh | ok | 29.2 | Predictive Failure Deasserted
ft1.fm0.fail | 3Eh | ok | 29.3 | Predictive Failure Deasserted

snip...

ft1.fm2.f0.speed | 46h | ok | 29.5 | 10000 RPM
ft0.fm0.f1.speed | 47h | ok | 29.0 | 9000 RPM

thanks
-Tuku-

The "cut" and "paste" utilities could be used for this (Boy, paste's a tool I havn't used in a while) but "awk" could be used for this as well and is probably simpler. Something like:
Code:

cat data.file | awk -F '|' '{print $1, "|", $4, "|", $5}'
where "data.file" is a file that contains the text you showed.

--
Rick

Tuku 01-04-2007 12:47 AM

Thanks.

-Tuku-


All times are GMT -5. The time now is 09:26 PM.