Re: File Manipulation in Linux
- From: Marc Schwartz <marc_schwartz@xxxxxxxxxxx>
- Date: Sat, 27 Jan 2007 19:45:04 -0600
Marc Schwartz wrote:
tman wrote:I want to search a text file for certain words and pipe them to another file, each word on a seperate line. Here is an example:
File1.txt
index: A name_110022763763
index: A name_110022028309
index: A name_110022162534
I want to search File1.txt for all the name_xxxxxxxxxxxx words and pipe them to another file each word on a seperate line. The other file would look like this:
File2.txt
name_110022763763
name_110022028309
name_110022162534
Does anyone know how to do this?
Thanks
This should work:
$ cat File1.txt
index: A name_110022763763
index: A name_110022028309
index: A name_110022162534
$ grep -o "name.*" File1.txt > File2.txt
$ cat File2.txt
name_110022763763
name_110022028309
name_110022162534
See 'man grep' for further help.
Here is one more solution:
cut -d' ' -f3 File1.txt > File2.txt
This uses 'cut' to take the third field in each line, where a space character is the delimiter between fields.
See 'man cut'
HTH (also)
Marc
.
- Follow-Ups:
- Re: File Manipulation in Linux
- From: Joe Cipale
- Re: File Manipulation in Linux
- References:
- File Manipulation in Linux
- From: tman
- Re: File Manipulation in Linux
- From: Marc Schwartz
- File Manipulation in Linux
- Prev by Date: Re: File Manipulation in Linux
- Next by Date: Re: LABEL managing on FC6
- Previous by thread: Re: File Manipulation in Linux
- Next by thread: Re: File Manipulation in Linux
- Index(es):
Relevant Pages
|