how to get one particular section (using awk)?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to get one particular section (using awk)?
# 8  
Old 10-28-2010
Thanks for all your replies!!

I ran the one line awk script and turn out to be symbol">" is missing in the output file. How can I can the ">" remained in the very beginning like ">ref|NP_253535.1|"?

I'll also be nice if you can explain to me what is "vRS".

Thanks!!
# 9  
Old 10-29-2010
Quote:
Originally Posted by DGPickett
Can RS= take a regex?
gawk can, but not awk/nawk (at least not on Solaris).

---------- Post updated at 07:48 AM ---------- Previous update was at 07:45 AM ----------

Quote:
Originally Posted by ritacc
Thanks for all your replies!!

I ran the one line awk script and turn out to be symbol">" is missing in the output file. How can I can the ">" remained in the very beginning like ">ref|NP_253535.1|"?

I'll also be nice if you can explain to me what is "vRS".

Thanks!!
see my previous post.
# 10  
Old 10-29-2010
Well, UNIX optarg can be confusing, especially when awk has multi-letter commands in non sh style mixed in. Probably equivalent to "-v RS=...". I am not an optarg fan, as it makes things confusing to save a key stroke or two: training and mistakes are more expensive. For instance, "-abcde" might mean "-a 'bcde'" or "-a -b 'cde'" OR . . . "-a -b -c -d -e" depending on which if any one letter option takes an argument.

https://www.unix.com/man-page/All/3/optarg/

Looks like xpg4 awk or nawk (new awk) or the wrong O/S man page:

Man Page for awk (OpenSolaris Section 1) - The UNIX and Linux Forums
Code:
	

awk(1)				 User Commands				awk(1)

NAME
       awk - pattern scanning and processing language

SYNOPSIS
       /usr/bin/awk [-f progfile] [-Fc] [' prog '] [parameters]
	    [filename]...

       /usr/xpg4/bin/awk [-FcERE] [-v assignment]... 'program' -f progfile...
	    [argument]...

# 11  
Old 10-29-2010
That woks! By the way, I don't have nawk on my mac and also linux red hat, so I use awk instead.

A further question, I have a list of names in one file, how do I get each of those and put together into one file by your "nawk" command?

I tried it by a naive guess, but it didn't return anything in outfile. The "mylist" file is the name list of all the entry name.
Code:
for i in mylist ; do awk -v str='$i' '$0~str{print RS $0}' RS='>' fasta-outCT-beta-q1; done > outfile

# 12  
Old 10-29-2010
Code:
while read i
do
  awk -v str="$i" '$0~str{print RS $0}' RS='>' fasta-outCT-beta-q1
done < mylist > outfile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to parse section of csv into array

In the awk below I am trying to parse the Sample Name below the section. The values that are extracted are read into array s(each value in a row seperated by a space) which will be used later in a bash script. The awk does execute but no values are printed. I am also not sure how to print in a row... (1 Reply)
Discussion started by: cmccabe
1 Replies

2. Shell Programming and Scripting

awk to lookup section of file in a range of another file

In the below, I am trying to lookup $1 and $2 from file1, in a range search using $1 $2 $3 of file2. If the search key from file1 is found in file2, then the word low is printed in the last field of that line in the updated file1. Only the last section of file1 needs to be searched, but I am not... (6 Replies)
Discussion started by: cmccabe
6 Replies

3. Shell Programming and Scripting

Extracting text from within a section of text using AWK

I have a command which returns the below output. How can I write a script to extract mainhost and secondhost from this output and put it into an array? I may sometimes have more hosts like thirdhost. I am redirecting this output to a variable. So I guess there should be a awk or sed command to... (7 Replies)
Discussion started by: heykiran
7 Replies

4. UNIX for Dummies Questions & Answers

Sorting arrays horizontally without END section, awk

input: ref001, Europe, Belgium, 1001 ref001, Europe, Spain, 203 ref001, Europe, Germany, 457 ref002, America, Canada, 234 ref002, America, US, 87 ref002, America, Alaska, 652 Without using an END section, I need to write all the info related to the same ref number ($1)and continent ($2) on... (9 Replies)
Discussion started by: lucasvs
9 Replies

5. Shell Programming and Scripting

using awk to get specific section of lines in logs

i have a log file that has the date and time that looks like this: Wed Jun 28 15:46:21 2012 test failed tailed passed passed not error panic what we want to focus on is the first 5 columns because they contain the date and time. the date and time can be anywhere on the line. in this... (6 Replies)
Discussion started by: SkySmart
6 Replies

6. Shell Programming and Scripting

Prepend first line of section to each line until the next section header

I have searched in a variety of ways in a variety of places but have come up empty. I would like to prepend a portion of a section header to each following line until the next section header. I have been using sed for most things up until now but I'd go for a solution in just about anything--... (7 Replies)
Discussion started by: pagrus
7 Replies

7. Shell Programming and Scripting

Extract section of file based on word in section

I have a list of Servers in no particular order as follows: virtualMachines="IIBSBS IIBVICDMS01 IIBVICMA01"And I am generating some output from a pre-existing script that gives me the following (this is a sample output selection). 9/17/2010 8:00:05 PM: Normal backup using VDRBACKUPS... (2 Replies)
Discussion started by: jelloir
2 Replies

8. Post Here to Contact Site Administrators and Moderators

New section

Hi Just a thought if it already hasn't been suggested. While looking at the forums I thought it might be a good idea under somewhere like 'special forums' add a section called 'projects'. I think this would be good for people to be able to post projects they have created. For example I am... (3 Replies)
Discussion started by: woofie
3 Replies

9. Shell Programming and Scripting

sed & awk--get section of file based 2 params

I need to get a section of a file based on 2 params. I want the part of the file between param 1 & 2. I have tried a bunch of ways and just can't seem to get it right. Can someone please help me out.....its much appreciated. Here is what I have found that looks like what I want....but doesn't... (12 Replies)
Discussion started by: Andy Cook
12 Replies

10. Post Here to Contact Site Administrators and Moderators

New Section

Just like we have a section "Unix for dummies..." , why not have a section on UNIX BACKUP AND RECOVERY Thanks :) (3 Replies)
Discussion started by: kapilv
3 Replies
Login or Register to Ask a Question