Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

grep then cut

Status
Not open for further replies.

hcclnoodles

IS-IT--Management
Jun 3, 2004
123
GB
Is it possible to grep for a particular word in a file and then cut those lines out of the original file into a new file

ie something like

grep STRING myfile | cut results > newfile

I know the above is rubbish but you get the general idea


any help would be greatly appreciated
 
Why not simply this ?
grep STRING myfile > newfile

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PHV thanks but i need to CUT the lines out of the original file, the above method leave them in the original file
 
awk '/STRING/{print >"newfile";next}{print}' myfile > myfile.new

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Code:
ex - myfile <<EOF
/STRING/d
wq!
EOF

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Code:
grep -v STRING myfile >newfile

The -v switch to grep does the inverse operation of normal grep. It outputs lines that do not match STRING.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top