LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to cut exact words within a file (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-cut-exact-words-within-a-file-572145/)

luzner 07-25-2007 07:38 AM

how to cut exact words within a file
 
I am trying the following command to cut the exact word "NO" from the the following text file .


cat tmp1 |tr -d 'NO' >> files

INT_CELL_KVZ_CDR_001980_20070722224203.DAT NO
INT_MAPA_KVZ_CDR_000309_20070722224203.DAT NO
INT_CELL_KVZ_CDR_001981_20070723225049.DAT NO
INT_MAPA_KVZ_CDR_000310_20070723225053.DAT NO
INT_CELL_KVZ_CDR_001982_20070724225507.DAT NO
INT_MAPA_KVZ_CDR_000311_20070724225511.DAT NO


the output is :

IT_CELL_KVZ_CDR_001980_20070722224203.DAT
IT_MAPA_KVZ_CDR_000309_20070722224203.DAT
IT_CELL_KVZ_CDR_001981_20070723225049.DAT
IT_MAPA_KVZ_CDR_000310_20070723225053.DAT
IT_CELL_KVZ_CDR_001982_20070724225507.DAT
IT_MAPA_KVZ_CDR_000311_20070724225511.DAT


it's not good because it's cutting all the "N" and not the exact word "NO"

how can I cut the exact word "NO" ?


Thanks

pixellany 07-25-2007 07:57 AM

In your first code example, you are appending to a file--is that what you intended?

I would use sed. For example, to remove all instances of "NO", do this:

sed 's/NO//g' < oldfile > newfile

luzner 07-25-2007 08:15 AM

thanks!
 
It's working thats what i intended

many thanks!


All times are GMT -5. The time now is 06:04 AM.