Contents and details extract problem asking...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Contents and details extract problem asking...
# 1  
Old 03-24-2010
Contents and details extract problem asking...

Input:
Code:
length    align    type    5453    8666    +
length    align    portion    5453    8666    +
length    align    range  5453    5616    +
length    align    name    5453    6121    +
length    align    age     5617    6121    +
length    align    name    7214    7404    +
length    align    age     7214    7404    +
length    align    name    8378    8666    +
length    align    age     8378    8416    +
length    align    average         8417    8666    +

length    align    type    33357   37495   -
length    align    portion    33357   37495   -
length    align    range  37341   37495   -
length    align    name    37065   37495   -
length    align    age     37065   37340   -
.
.

Output:
Code:
length    5453    6121    
length    7214    7404    
length    8378    8666    

length    37495   37065
.
.

All the portion is separated by a new line or "type". Under the "type", I only need to focus on the data with "name" at the column3. For those that "name" at the column3 and column6 is marked as "+", the data of column4 and column5 can be maintained. While those that "name" at the column3 and column6 is marked as "-", the data of column4 and column5 should be reversed. It seems like awk able to archive these goal.
Thanks for any advice.
# 2  
Old 03-24-2010
Try...
Code:
awk '$3=="name"{print $1, ($6=="+"?$4 OFS $5:$5 OFS $4)}' OFS=\\t file1

# 3  
Old 03-31-2010
Hi Ygor,
Thanks a lot for your awk code suggestion.
It worked well.
but it seems like it can't separated all the portion by a new line based on "type" word.
my desired output:
Code:
length    5453    6121    
length    7214    7404    
length    8378    8666    

length    37495   37065
.
.

The output after I run your awk code:
Code:
length    5453    6121    
length    7214    7404    
length    8378    8666    
length    37495   37065
.
.

Both of the output are quite close to each other except lack of the new line based on the "type" word. Do you got any idea to archive my desired output result?
Thanks a lot and again for your help.
# 4  
Old 03-31-2010
Try this:
Code:
awk '{ if(($3 == "name") && ($6 == "+")) {print $1,$4,$5 } else if(($3 == "name") && ($6 == "-"))  {print "\n" $1,$5,$4}}' file1


Last edited by Franklin52; 03-31-2010 at 08:34 AM.. Reason: Please use code tags!
# 5  
Old 03-31-2010
Hi Jairaj,
Your awk code seems like still got a bit different to generate my desired output result?
Do you got other suggestion or advice to improve it?
Thanks again first.
I'm trying to edit your awk code to get my desired output result as well...
# 6  
Old 03-31-2010
With a little adaptation of the code of Ygor:
Code:
awk '$3=="name"{print $1, ($6=="+"?$4 OFS $5:$5 OFS $4)}!NF{print ""}' OFS=\\t file1

# 7  
Old 03-31-2010
Thanks for your help again, Franklin52.
Your awk code work perfectly in my case.
Thanks again.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to extract jil file details in a excelsheet

I am very new to shell scripting. I have a autosys jil file that looks like :-- /* ------------- JOB1 ------------------ */ insert_job: JOB1 job_type: b owner: cm@pelonmuck permission: gx,ge,wx,we,mx,me date_conditions: 1 days_of_week: mo,tu,we,th,fr,su start_time: "18:30"... (9 Replies)
Discussion started by: newbie_shell
9 Replies

2. Shell Programming and Scripting

Extract both contents from a html file and do printing

Hi there, Print IP Address: grep 'HostID :' 10.244.9.124\ nessus.html | awk -F '<br>' '{print $12}' | tr -s ' ' | awk -F ':' '{print "<tr><td>" $2 "</td><td>"}' Print Respective Ports: grep 'classsubsection\|./tcp\|./udp' 10.244.9.124\ nessus.html | grep -v 'h2.classsubsection... (3 Replies)
Discussion started by: alvinoo
3 Replies

3. Shell Programming and Scripting

Extract sentence and its details from a text file based on another file of sentences

Hi I have two text files. The first file is TEXTFILEONE.txt as given below: <Text Text_ID="10155645315851111_10155645333076543" From="460350337461111" Created="2011-03-16T17:05:37+0000" use_count="123">This is the first text</Text> <Text Text_ID="10155645315851111_10155645317023456"... (7 Replies)
Discussion started by: my_Perl
7 Replies

4. UNIX for Dummies Questions & Answers

Extract specific contents from each line

Hi all, Happy new year! Here I have a problem with extract specific information from each line in unix: My file is the dbSNP flat file, take two SNPs for examples: REFSNP-DOCSUM-SET (FULL-DUMP) CREATED ON: 2012-06-08 10:50 rs782 | human | 9606 | snp | genotype=NO |... (6 Replies)
Discussion started by: luoruicd
6 Replies

5. Shell Programming and Scripting

Formatting Report and Reading data and fetching the details from contents file

Data I was trying to write shell script which will be return the output in the below format First i was trying to do these using sed. sed -n '/.ksh/p' mainksh.ksh sed -e 's/*\(.*\)/\1/g' mainksh.ksh $RUN_DIR, $SUB_DIR and the variables which will be defined in the profile file. when i am... (0 Replies)
Discussion started by: rameshds
0 Replies

6. Shell Programming and Scripting

Extract contents of tar ball without extracting files

Hi, I'm using a tar command tar -xOvf /home/mytar.tar My intention is to extract data in files which are inside various directories, without extracting files to the disk. Is this the best way to achieve it? Thanks, Chetan (3 Replies)
Discussion started by: chetan.c
3 Replies

7. Shell Programming and Scripting

Extract details from XML file

Hi , I have one xml file contains more than 60 lines. I need to extract some details from the file and store it in new file.Not the whole file Please find the xml file below: <?xml version="1.0" encoding="UTF-8"?> <DeploymentDescriptors xmlns="http://www.tibco.com/xmlns/dd"> ... (6 Replies)
Discussion started by: ckchelladurai
6 Replies

8. UNIX for Dummies Questions & Answers

How to extract contents of ONLY one directory from ZIP folder.

I have a ZIP folder ( folder.zip or folder.jar ) which contains , lets say 3 directories under it ( directory1, directory2, directory3). How can i unzip the contents of directory2 ONLY ? I do not have to unzip the complete folder. TIA. (2 Replies)
Discussion started by: Sheel
2 Replies

9. Shell Programming and Scripting

Shell script or command help to extract specific contents from a long list of content

Hi, I got a long list of contents: >sequence_1 ASSSSSSSSSSSDDDDDDDDDDDCCCCCCC ASDSFDFFDFDFFWERERERERFSDFESFSFD >sequence_2 ASDFDFDFFDDFFDFDSFDSFDFSDFSDFDSFASDSADSADASD ASDFFDFDFASFASFASFAFSFFSDASFASFASFAFS >sequence_3 VEDFGSDGSDGSDGSDGSDGSDGSDG dDFSDFSDFSDFSDFSDFSDFSDFSDF... (2 Replies)
Discussion started by: patrick87
2 Replies

10. Shell Programming and Scripting

i want to extract details for particular file

Hi i have following file uuid ( RO) : 62701790-60da-dd9a-669d-a563aac1c435 host-uuid ( RO): 5f3f668d-a7c7-4e5f-a4a6-6e90fafb50ed sr-uuid ( RO): 62103d07-e0aa-acf3-2d9f-414ad3377bd0 device-config (MRO): location: /dev/xapi/block ... (6 Replies)
Discussion started by: bp_vardhaman
6 Replies
Login or Register to Ask a Question