Re: File Manipulation in Linux



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
.



Relevant Pages

  • Re: File Manipulation in Linux
    ... I want to search File1.txt for all the name_xxxxxxxxxxxx words and pipe them to another file each word on a seperate line. ... $ cat File1.txt ... This uses 'cut' to take the third field in each line, where a space character is the delimiter between fields. ... I would have offered to use a combo of 'awk' and 'grep'. ...
    (linux.redhat)
  • Re: File Manipulation in Linux
    ... tman wrote: ... I want to search File1.txt for all the name_xxxxxxxxxxxx words and pipe them to another file each word on a seperate line. ... $ cat File1.txt ... Marc Schwartz ...
    (linux.redhat)
  • Re: comparing two files yy.unl and xx.dat
    ... You could use cut on one file to seperate each field to a seperate file, ... $ cat xx.dat ... Bluescreen leads to downtime. ... Downtime leads to suffering. ...
    (freebsd-questions)
  • Re: OpenBSD 3.5 Internet Gateway
    ... >>cat nat.conf ... I wanted to seperate the NAT rules, but afterwards i decided to put ...
    (comp.unix.bsd.openbsd.misc)