awk and combining lines to stdout


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk and combining lines to stdout
# 1  
Old 04-18-2011
awk and combining lines to stdout

I am trying to come up with a good approach to taking a file and only printing 10 columns.
The input file has duplicate lines but only the 6th column has real value.
I just need to combine the lines and output 1 line per
example file:
Code:
1 2.0765 AA 10 0.6557 .....
1 2.0765 AA 10 0.6655 .....
2 2.0855 AB 11 0.6556 .....
2 2.0855 AB 11 0.6557 ......
3 2.0811 AC 12 0.6559 ......
3 2.0811 AC 12 0.6565 ......

I am using awk
Code:
awk -v FS="\t" -v OFS="\t" 'BEGIN {which_line=1} 
        which_line==1 {
                        value=$10
                        which_line=2
                        }
        which_line==2 {
                        value2=$10
                        which_line=1
                }
        {print $6, $1, $4, $2, $3, value, value2}'

-- this prints out both lines ------

tried this method (trimmed it back to a basic output)
Code:
awk -v FS="\t" -v OSF="\t" '{ if ((NR %2) ==0 {printf("%s\n", $0) else {printf("%s ",$0)}}'

Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 04-18-2011 at 03:11 PM.. Reason: code tags, please!
# 2  
Old 04-18-2011
If you only care about the 6th column, why not awk '{ print $6; }' ? What do you actually want the output data to be?
# 3  
Old 04-18-2011
Can you post a sample of the input file with the 6th col. in it and how the output should look like.
# 4  
Old 04-18-2011
Apologies, i want the 4 columns from the first line and only the 6th column from the second line. output combined in one line.

currently my print comes out in two lines.
# 5  
Old 04-18-2011
how about a sample of input and output...
# 6  
Old 04-18-2011
i trimmed the files to keep it easier but here is my input file:
Code:
1    A    01    Plate_1    1    A3059GVS    sample    cib    Endogenous Control    25.37016    0.6680705                                                Automatic            Manual    0.0    279002692             
1    A    01    Plate_1    1    A3059GVS    sample    gypsy    Target    Undetermined    -0.0058518443                                                Automatic            Manual    0.0    279002692             
2    A    01    Plate_2    2    A3059GVS    sample    cib    Endogenous Control    26.642002    0.78160816                                                Automatic            Manual    0.0    279002692             
2    A    01    Plate_2    2    A3059GVS    sample    gypsy    Target    Undetermined    0.0094884625                                                Automatic            Manual    0.0    279002692             
3    A    02    Plate_1    3    A3059GVS    sample    cib    Endogenous Control    25.381462    0.6007404                                                Automatic            Manual    0.0    279002692             
3    A    02    Plate_1    3    A3059GVS    sample    gypsy    Target    Undetermined    -0.004894779                                                Automatic            Manual    0.0    279002692             
4    A    02    Plate_2    4    A3059GVS    sample    cib    Endogenous Control    26.452559    0.7159146                                                Automatic            Manual    0.0    279002692             
4    A    02    Plate_2    4    A3059GVS    sample    gypsy    Target    Undetermined    0.0018055962                                                Automatic            Manual    0.0    279002692

----------------------------------------------------------

The second line where it says "Undetermined" is actually meaningful. I need to add that column on the same line as the first line in the output. The actual file has 2650 lines. The columns that are meaningfull are ($6, $1, $4, $2, $10, $11) for my new output.
Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 04-18-2011 at 04:46 PM.. Reason: once again - code tags, PLEASE!
# 7  
Old 04-18-2011
Add it where, though?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Combining lines in one line

Hi below is the input file snippet. here i want that all the line which is coming after 1 shoud be in one line. so for exanple if after 1 there is two lines which is starting with 2 should be combine in one line. input file content 1,8091012,BATCH_1430903_01,21,T,2,808738,,,,21121:87:01,... (19 Replies)
Discussion started by: scriptor
19 Replies

2. Shell Programming and Scripting

Combining two lines into one, UNIX

Hi All, I have a file which has the following sample lines -- <Member name="Canada" Currency="CAD" -- <Member name="UK" Currency="GBP" -- <Member name="Switzerland" Currency="CHF" -- <Member name="Germany" Currency="EUR" -- (11 Replies)
Discussion started by: dev.devil.1983
11 Replies

3. Shell Programming and Scripting

Reading two lines in a while loop and combining the lines

Dear all, I have a file like this: imput scaffold_0 1 scaffold_0 10000 scaffold_0 20000 scaffold_0 25000 scaffold_1 1 scaffold_1 10000 scaffold_1 20000 scaffold_1 23283 and I want the output like this: scaffold_0 1 scaffold_0 10000 scaffold_0 10000 scaffold_0 20000... (6 Replies)
Discussion started by: valente
6 Replies

4. Shell Programming and Scripting

Combining lines between two specific lines

Hi, I have a requirement like following: I have input file like: Question: 1 ----Multiple choice--- What is your favourite colour? Options: a) red b) blue c) none of these Question: 2 ---Multiple choice----- In which month did you join your first job? Options: a) Jan b) Feb c)... (11 Replies)
Discussion started by: ppatra
11 Replies

5. Shell Programming and Scripting

Combining many lines to one using awk or any unix cmd

Combining many lines to one using awk or any unix cmd Inputfile: Output : Appreciate help on this. (14 Replies)
Discussion started by: pinnacle
14 Replies

6. Shell Programming and Scripting

Combining two text lines into one

Here is the sample file: 646 STARTED Tue Dec 30 06:38:53 2008 Job DdCustXAddr_brad has been reset. 647 STARTED Tue Dec 30 06:38:54 2008 Starting Job DdCustXAddr_brad. (...) 704 STARTED Tue Dec 30 06:49:02 2008 Job DdCustXAddr_brad aborted. I want to combine every non-numbered line... (4 Replies)
Discussion started by: mfavero
4 Replies

7. Shell Programming and Scripting

combining lines in files

hey, I want to combine every three lines in a file onto one i.e old file: 82 67 32 62 58 39 29 47 58 27 34 50 27 35 69 38 58 70 new file: 82 67 32 62 58 39 29 47 58 27 34 50 27 25 69 38 58 70 At the moment I am using the following code: gawk 'BEGIN {x=0} { if(x<3)... (14 Replies)
Discussion started by: sme
14 Replies

8. Shell Programming and Scripting

combining lines between 2 pattern using awk

Hi I am fairly new to shell scripting i have some file with outout 1011 abc fyi 6.1.4.5 abr tio 70986 dfb hji 4.1.7 ....some text 111114 i have to format this text to 1011 abc fyi 6.1.4.5 abr tio 70986 dfb hji 4.1.7 ....some text 111114 (3 Replies)
Discussion started by: shell.scriptor
3 Replies

9. Shell Programming and Scripting

help combining lines in awk

I seem to have gotten myself in over my head on this one. I need help combining lines together. I have a text file containing 24,000 lines (exactly why I need awk) due to bad formatting it has separated the lines (ideally it should be 12,000 lines total). Example of file: ... (2 Replies)
Discussion started by: blueheed
2 Replies

10. Shell Programming and Scripting

need help appending lines/combining lines within a file...

Is there a way to combine two lines onto a single line...append the following line onto the previous line? I have the following file that contains some blank lines and some lines I would like to append to the previous line... current file: checking dsk c19t2d6 checking dsk c19t2d7 ... (2 Replies)
Discussion started by: mr_manny
2 Replies
Login or Register to Ask a Question