Re: File Manipulation in Linux
- From: Joe Cipale <joec@xxxxxxxxxxx>
- Date: Sat, 27 Jan 2007 19:37:08 +0000
Marc Schwartz wrote:
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
I would have offered to use a combo of 'awk' and 'grep'. One script and multiple output files
Of course, perl would also work quite nicely as well.
.
- Follow-Ups:
- Re: File Manipulation in Linux
- From: ynotssor
- Re: File Manipulation in Linux
- References:
- File Manipulation in Linux
- From: tman
- Re: File Manipulation in Linux
- From: Marc Schwartz
- Re: File Manipulation in Linux
- From: Marc Schwartz
- File Manipulation in Linux
- Prev by Date: Re: my 56k dialup internal modem (V.92 Data/Fax/Voice) is not working on linux
- Next by Date: how to start VNC on boot
- Previous by thread: Re: File Manipulation in Linux
- Next by thread: Re: File Manipulation in Linux
- Index(es):
Relevant Pages
|
|