Login or Register to Ask a Question and Join Our Community


removing unneeded information from grep?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers removing unneeded information from grep?
# 1  
Old 08-20-2001
removing unneeded information from grep?

Im looking for a way to setup a lil' script that will read the output from a command and dump certain items from that into another file

for an example, im trying this
cat test | grep "statement" > test.answer

but its giving me the full line that it finds
is there any way to take out a portion of text from before what i want and after what i want?

as in, I am searching for address=here
so i: cat test | grep "here" > test.answer
and i want to get rid of the parts before and after the word 'here'...is there anyway to do this?

Thanks
David
# 2  
Old 08-20-2001
awk or perl

First to choices that come to mind:

awk and PERL


I prefer PERL more than the grep/awk combo. The beauty of these utlities is that there are many, many ways to accomplish these routine tasks.
# 3  
Old 08-20-2001
Bug Re

Try this for example

cat FILE_NAME | awk '{print $1}' > ouput_file

This will take out the first field in FILE_NAME and put it in the output_file

Best bet is to look up awk, there are some good examples in the man page.
# 4  
Old 08-20-2001
Network =(

thanks, now i need to know how to get it to parse..
i had already tried the man pages for awk (but they didnt really help me figure much of anything out)
and i tried using it with awk like:

cat file | awk '(print $1)' > testfile

and its giving me parse errors
so i tried to pipe it from grep and get the same thing

awk: cmd. line:1: (print $1)
awk: cmd. line:1: ^ parse error
awk: cmd. line:2: (print $1)
awk: cmd. line:2: ^ unexpected newline

so i move the > testfile to right afer ther $1)' (took out the whitespace) and got the same thing. Im not all that good with scripting or debugging so if I could get some help on this one too please. btw, I'm also using slackware on 2.2.19 if that helps any.

Thanks
# 5  
Old 08-20-2001
You are experience syntax problems with AWK. It takes a while to get used to it Smilie Find some simple examples in the texts and you will be running smooth in no time.
# 6  
Old 08-20-2001
Tools oopsie

okay, scratch that last one
i was using ()'s instead of {}'s
no errors now=)

Thanks again
# 7  
Old 08-20-2001
Re

I think your using the wrong brackets..

You sould be using the ones { } and not ( )
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed / awk / grep to extract information from log

Hi all, I have a query that runs that outputs data in the following format - 01/09/12 11:43:40,ADMIN,4,77,Application Group Load: Name(TESTED) LoadId(5137-1-0-1XX-15343-15343) File(/dir/dir/File.T03.CI2.RYR.2012009.11433350806.ARD) InputSize(5344) OutputSize(1359) Rows(2) Time(1.9960)... (8 Replies)
Discussion started by: jeffs42885
8 Replies

2. Solaris

Remove unneeded Ethernet devices?

Solaris 10 x86 VM was shipped with four NICs, two each teamed together. We don't want or need. I ifconfig downed e1000g2 and e1000g3 and removed their /etc/hostname.* entries. But the kernel still sees those devices, and I'm not sure how to remove them. They have been removed from the VM... (5 Replies)
Discussion started by: jnojr
5 Replies

3. UNIX for Dummies Questions & Answers

Removing PATTERN from txt without removing lines and general text formatting

Hi Everybody! First post! Totally noobie. I'm using the terminal to read a poorly formatted book. The text file contains, in the middle of paragraphs, hyphenation to split words that are supposed to be on multiple pages. It looks ve -- ry much like this. I was hoping to use grep -v " -- "... (5 Replies)
Discussion started by: AxeHandle
5 Replies

4. Shell Programming and Scripting

Include information in certain columns using grep and awk

HI all, I have data in a file that looks like this: 1 HOW _ NNP NNP _ 3 nn _ _ 2 DRUGS _ NNP NNP _ 3 nn _ _ 3 ACT _ NNP NNP _ 0 null _ _ 4 : _ ... (3 Replies)
Discussion started by: owwow14
3 Replies

5. Shell Programming and Scripting

Inconsistent `ps -eaf -o args | grep -i sfs_pcard_load_file.ksh | grep -v grep | wc -l`

i have this line of code that looks for the same file if it is currently running and returns the count. `ps -eaf -o args | grep -i sfs_pcard_load_file.ksh | grep -v grep | wc -l` basically it is assigned to a variable ISRUNNING=`ps -eaf -o args | grep -i sfs_pcard_load_file.ksh |... (6 Replies)
Discussion started by: wtolentino
6 Replies

6. UNIX for Dummies Questions & Answers

Grep from pattern file without removing duplicates?

I have been using grep to output whole lines using a pattern file with identifiers (fileA): fig|562.2322.peg.1 fig|562.2322.peg.3 fig|562.2322.peg.3 fig|562.2322.peg.3 fig|562.2322.peg.7 From fileB with corresponding identifiers in the second column: NODE_0 fig|562.2322.peg.1 peg ... (2 Replies)
Discussion started by: Mauve
2 Replies

7. UNIX for Dummies Questions & Answers

Grep? - using a file of terms to search another file when the information is on a different line

I have a flat file that looks like this, let's call it Chromosome_9.txt: FT /Gene_Name="Guanyl-Acetylase 9" FT /Gene_Number"36952" FT /Gene_Name="Endoplasmic Luciferase" FT /Gene_Number"36953" FT ... (4 Replies)
Discussion started by: Twinklefingers
4 Replies

8. Shell Programming and Scripting

Grep'ing information from a log file on SUN OS 5

Hi Guys, I'm trying to write an script that will be launched by a user. The script will look at a log file and check for alerts with the date (supplied by user) and a machine's hostname (also supplied by the user). I'm trying to get the output formatted just like the log file. The logfile looks... (5 Replies)
Discussion started by: illgetit
5 Replies

9. Shell Programming and Scripting

copying file information using awk & grep

Hi, TASK 1: I have been using this code to print the information of files kept at "/castor/cern.ch/user/s/sudha/forPooja" in some text file name FILE.txt. rfdir /castor/cern.ch/user/s/sudha/forPooja | grep data | awk '{print "rfio:///castor/cern.ch/user/s/sudha/forPooja/"$9}' > FILE.txt ... (6 Replies)
Discussion started by: nrjrasaxena
6 Replies

10. UNIX for Advanced & Expert Users

How to perform Grep on many Gzip files, Searching for Specific information

Hello, I am wondering if you can assist with my question and ask kindly for this. I have a number of files that are listed as file1.gz through file100.gz. I am trying to perform a grep on the files and find a specific date that only resides within within one of the files. There are... (3 Replies)
Discussion started by: legharb
3 Replies
Login or Register to Ask a Question

Featured Tech Videos