Using grep to make a header


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Using grep to make a header
# 1  
Old 09-14-2014
Using grep to make a header

How would I do the following :
  1. Records other than ”ATOM”,”CONNECT”, ”HETATM”, ”TER” and ”END” are considered header records which describe the metadata about the molecule. Use grep to generate the header.
I have this chemistry database. On the attachment. But I am not sure how to use grep to find a header, all know it to find patterns.
# 2  
Old 09-14-2014
What have you tried so far and what is your expected output?

Are you simply wishing to grep and display all the records containing those key words?
# 3  
Old 09-14-2014
I did

Code:
grep -wnv atom connect ter 4hkd.txt

to display the I guess part of the text without atom, connect,ter these words. But now I have to make it into header somehow.

Last edited by Don Cragun; 09-14-2014 at 04:45 PM.. Reason: Add CODE tags.
# 4  
Old 09-14-2014
Is this a homework assignment? This is the wrong forum for homework assignments.

Have you looked at your input file? Do you see any lowercase letters in your input file?
Do you see any occurrences of CONNECT or connect in your input file?

Your command:
Code:
grep -wnv atom connect ter 4hkd.txt

is looking for the string atom (in lowercase) and printing every line that does not contain a word that matches that string (preceded by its line number) from the files connect, ter, and 4hkd.txt.
# 5  
Old 09-15-2014
I suggest you issue

Code:
man grep

at the commandline and read what comes up there. This is generally a good idea, btw.: whenever you want to know how too use a command, issue man command to get the manual entry about command.

I suggest you pay special attention to the "-v" switch of grep.

I hope this helps.

bakunin
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find header in a text file and prepend it to all lines until another header is found

I've been struggling with this one for quite a while and cannot seem to find a solution for this find/replace scenario. Perhaps I'm getting rusty. I have a file that contains a number of metrics (exactly 3 fields per line) from a few appliances that are collected in parallel. To identify the... (3 Replies)
Discussion started by: verdepollo
3 Replies

2. Shell Programming and Scripting

Grep Data Base on Header

HI Guys, File A.txt UID,HD1,HD2,HD3,HD4 1,2,33,44,55 2,10,14,15,16 File B.txt UID HD1 HD4 A.txt B.txt >>>Output.txt UID,HD1,HD4 1,2,55 2,10,16 (11 Replies)
Discussion started by: pareshkp
11 Replies

3. Shell Programming and Scripting

Make copy of text file with columns removed (based on header)

Hello, I have some tab delimited text files with a three header rows. The headers look like, (sorry the tabs look so messy). index group Name input input input input input input input input input input input... (9 Replies)
Discussion started by: LMHmedchem
9 Replies

4. Shell Programming and Scripting

Problems with using grep to make backups to a different directory

I am trying to program a script that is using grep to find lines in a file in my home directory, and then use a pipe command to copy what is shown into different files in a different directory to create backup files. When I run it, though, it only creates a copy of the file that grep was going... (7 Replies)
Discussion started by: sammythesp3rmy
7 Replies

5. Shell Programming and Scripting

Flat file-make field length equal to header length

Hello Everyone, I am stuck with one issue while working on abstract flat file which i have to use as input and load data to table. Input Data- ------ ------------------------ ---- ----------------- WFI001 Xxxxxx Control Work Item A Number of Records ------ ------------------------... (5 Replies)
Discussion started by: sonali.s.more
5 Replies

6. UNIX for Dummies Questions & Answers

how to make this grep command

/usr/xpg4/bin/grep -e "Type" / datarecords.txt output datarecords.txt: male | datarecords.txt: male | datarecords.txt: female i wanna the output to be :male | :male | :female at the end not to appear the filename fom grep command :D :D (3 Replies)
Discussion started by: teefa
3 Replies

7. AIX

How to make grep stop at first match

I use grep to check for a string that validates data in a file, it works great but the problem is that the file is becoming too big and gerp has started hurting the response time to users. Since I only need to find the first occurrence I have been looking for ways to stop grep for scanning the rest... (8 Replies)
Discussion started by: mpoblete
8 Replies

8. Shell Programming and Scripting

grep files without header and move to new dir

Hi, i have number of files in a directory to be processed. the problem is some of the files does not have a header and the process is giving an error of no header found. example of good file : file1 HDR|20080803233401 record 1 record 2 TRA|2 example of a bad file in the same dir ... (6 Replies)
Discussion started by: sitaldip
6 Replies

9. UNIX for Dummies Questions & Answers

grep data from header of files

Hello I want to grep data from header of the files . The header conatins data in this format . # $maint$ test1 # $product$ TTT I want to store maint name and product name with path of file . (12 Replies)
Discussion started by: getdpg
12 Replies

10. Shell Programming and Scripting

Make grep -c display like grep -n?

Hey Guys, Wondering if there is a way to do the following I have a file called test.txt abc def abc abc def I have a pattern file called pattern.txt containing the following abc def I want to do a count, but have it display the count value preceeding each line like grep -n (2 Replies)
Discussion started by: Jerrad
2 Replies
Login or Register to Ask a Question