Cut Lines using grep


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cut Lines using grep
# 1  
Old 08-10-2012
Cut Lines using grep

Hi,

I have a SQL script with "create table" and "alter table" statements and I want to cut all the alter table statements from original file (A) and move it to a different file (B).

Can you please me the option. Thanks a lot for your time.
# 2  
Old 08-10-2012
Code:
# Assuming all your lines are in lower case
egrep "create table|alter table" file_a > file_b
# Or if they are mixed case or upper case
egrep -i "create table|alter table" file_a > file_b

# 3  
Old 08-10-2012
Thanks for your reply.

Will egrep cut the lines from file_a?
# 4  
Old 08-11-2012
Yes. egrep is just version of grep which in this context will do an or comparison. It's the same as grep -E.
As the command I posted does not affect the original file, while not try it?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Cut particular lines

All, I would like to cut all the lines from the log file for the timestamp . I'm not clear about how to apply grep ,awk here.Can you help me on this ? My logfile: ********** Wed Feb 20 03:48:26 2013 Thread 1 advanced to log sequence 400 (LGWR switch) Thu Feb 21 02:34:23 2013... (1 Reply)
Discussion started by: arul1185
1 Replies

2. Shell Programming and Scripting

grep with cut option??

This is my command-line code in my script, passwd=`grep $passwd $userfile | cut -f2 -d: login_users > retrieve` the cut -f2 -d: login_users > retrieve searches and prints the whole column two. what I need is one of the items in the column two only.. what option can I add to my cut... (2 Replies)
Discussion started by: jenimesh19
2 Replies

3. Shell Programming and Scripting

Perl XML, find matching condition and grep lines and put the lines somewhere else

Hi, my xml files looks something like this <Instance Name="New York"> <Description></Description> <Instance Name="A"> <Description></Description> <PropertyValue Key="false" Name="Building A" /> </Instance> <Instance Name="B"> ... (4 Replies)
Discussion started by: tententen
4 Replies

4. Slackware

How should I cut this line using cut and grep?

not sure how to do it. wan't to delete it using cut and grep ince i would use it in the shell. but how must the command be? grep "64.233.181.103 wwwGoogle.com" /etc/hosts | cut -d the delimeter is just a space. can you help meplease. :D (1 Reply)
Discussion started by: garfish
1 Replies

5. Shell Programming and Scripting

AIX equivalent to GNU grep's -B and -A [print lines after or before matching lines]

Hi folks I am not allowed to install GNU grep on AIX. Here my code excerpt: grep_fatal () { /usr/sfw/bin/gegrep -B4 -A2 "FATAL|QUEUE|SIGHUP" } Howto the same on AIX based machine? from manual GNU grep ‘--after-context=num’ Print num lines of trailing context after... (4 Replies)
Discussion started by: slashdotweenie
4 Replies

6. Shell Programming and Scripting

Using grep and cut within awk

Hi My input file looks like as follows: say a.txt "aaaa cc","224 AW","ss cccccc","P06 09/10","dddddd" "aaaa cc","224 AW","ss cccccc","P06 09/10","dddddd" "aaaa cc","224 AW","ss cccccc","P06 09/10","dddddd" "aaaa cc","224 AW","ss cccccc","P06 09/10","dddddd" "aaaa cc","224 AW","ss... (5 Replies)
Discussion started by: bittoo
5 Replies

7. UNIX for Dummies Questions & Answers

grep and cut problem

Hello folks, I have to (e)grep out a certain pattern e.g. <TAG1> from a huge log file which does not have any space as such. The thing is that once I have 'grep'ed out the <TAG1> from the file I need to extract the content within the tags, i.e, <TAG1>Data_To_Be_Extracted</TAG1> The underlined... (9 Replies)
Discussion started by: Rajat
9 Replies

8. Shell Programming and Scripting

tail, grep and cut

Hello all, I have some weird problem that kinda baffles me. Say I have the following test file: claudia:~/tmp$ cat testfile.txt This is a test line This is the second test line And yeah, this is the third test line Then say I want to tail the file, grep for the word "third" then... (7 Replies)
Discussion started by: sylaan
7 Replies

9. Shell Programming and Scripting

cut sed grep or other?

Hi Is there a way to cut the last two characters off a word or number given that this word or number can be of varying length? I have tried something like TEST=`echo $OLD | cut -c 1-5` where $OLD is a variable containing a number like 1234567 which gives a result of 12345. This is fine... (4 Replies)
Discussion started by: rleebife
4 Replies

10. Shell Programming and Scripting

grep and cut....

hi, i have a simple question: in hpux 11i; this cmd : cat mailtest |grep sekar >test1 gives the output file with the name test1. i want to remove the line which contains the "sekar" and put the result in the new file.... what is the command for that?.. (2 Replies)
Discussion started by: sekar sundaram
2 Replies
Login or Register to Ask a Question