Sponsored Content
Top Forums Shell Programming and Scripting create pipes based on the column Post 302390366 by ramse8pc on Wednesday 27th of January 2010 05:48:50 PM
Old 01-27-2010
create pipes based on the column

i get text files with
Code:
Action & Adventure|2012: Supernova NR|2009-11-01 00:01:00|2010-05-01 23:59:00|Active|3
Action & Adventure|50 Dead Men Walking|2010-01-05 00:01:00|2010-06-30 23:59:00|Active|4
Action & Adventure|Afterwards|2009-11-26 00:01:00|2010-03-26 23:59:00|Deactivated|6

Based on the last column value of the row, i have to insert number of pipes after the 2nd column.

i know the way how to create if it is 3, 4, etc.. like.
Code:
awk -F"|" '$NF==3{{printf "%s|%s",$1,$2}{for(i=0;i<=$NF;i++){printf "|"}}{printf "%s|%s|%s|%s|\n",$3,$4,$5,$6}}' a.txt > F.txt 
awk -F"|" '$NF==4{{printf "%s|%s",$1,$2}{for(i=0;i<=$NF-1;i++){printf "|"}}{printf "%s|%s|%s|%s|\n",$3,$4,$5,$6}}' b.txt >FF.txt

My problem is i can't hard code like $NF==3, $NF==4 for each value as we don't know the value that is coming in the file.
Is there a way to do it for any value in the last column?

Thanks in advance.

Last edited by Scott; 01-27-2010 at 07:01 PM.. Reason: Code tags, please...
 

10 More Discussions You Might Find Interesting

1. Filesystems, Disks and Memory

PIPEs and Named PIPEs (FIFO) Buffer size

Hello! How I can increase or decrease predefined pipe buffer size? System FreeBSD 4.9 and RedHat Linux 9.0 Thanks! (1 Reply)
Discussion started by: Jus
1 Replies

2. Shell Programming and Scripting

how to use pipes + redirection to create two files?

# this works # creates two.txt (echo one;echo two;echo three;) | ( ( grep two > two.txt ) ) # wamt this to create two files: # two.txt containing "two" and three.txt containing "three" # Both files get created, but three.txt is empty # is there a way to do this? (echo one;echo two;echo... (3 Replies)
Discussion started by: tphyahoo
3 Replies

3. Shell Programming and Scripting

Create files based on second column of a file

Hi All, I have a file which looks like this: 234422 1 .00222 323232 1 3232 32323 1 0.00222 1234 2 1211 2332 2 0.9 233 3 0.883 123 3 45 As you can see, the second column of the file is already sorted which I did using sort command. Now, I want to create files based on the second... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

4. Shell Programming and Scripting

to add special tag to a column based on column condition

Hi All, I have following html code <TR><TD>9</TD><TD>AR_TVR_TBS </TD><TD>85000</TD><TD>39938</TD><TD>54212</TD><TD>46</TD></TR> <TR><TD>10</TD><TD>ASCV_SMY_TBS </TD><TD>69880</TD><TD>33316</TD><TD>45698</TD><TD>47</TD></TR> <TR><TD>11</TD><TD>ARC_TBS ... (9 Replies)
Discussion started by: ckwan
9 Replies

5. Shell Programming and Scripting

AWK script to create max value of 3rd column, grouping by first column

Hi, I need an awk script (or whatever shell-construct) that would take data like below and get the max value of 3 column, when grouping by the 1st column. clientname,day-of-month,max-users ----------------------------------- client1,20120610,5 client2,20120610,2 client3,20120610,7... (3 Replies)
Discussion started by: ckmehta
3 Replies

6. Shell Programming and Scripting

awk to sum a column based on duplicate strings in another column and show split totals

Hi, I have a similar input format- A_1 2 B_0 4 A_1 1 B_2 5 A_4 1 and looking to print in this output format with headers. can you suggest in awk?awk because i am doing some pattern matching from parent file to print column 1 of my input using awk already.Thanks! letter number_of_letters... (5 Replies)
Discussion started by: prashob123
5 Replies

7. Shell Programming and Scripting

Create new file with increment column based on conditions

Hello, Using bash script, i need to process the following file: 887,86,,2013-11-06,1,10030,5,2,0,200,, 887,86,,2013-11-05,1,10030,5,2,0,199,, 887,138,,2013-11-06,1,10031,6,2,0,1610612736,, 887,164,,2013-11-06,1,10000,0,2,0,36000,, and to create a new file such as the below ... (2 Replies)
Discussion started by: JonhyDeep
2 Replies

8. Shell Programming and Scripting

Sum column values based in common identifier in 1st column.

Hi, I have a table to be imported for R as matrix or data.frame but I first need to edit it because I've got several lines with the same identifier (1st column), so I want to sum the each column (2nd -nth) of each identifier (1st column) The input is for example, after sorted: K00001 1 1 4 3... (8 Replies)
Discussion started by: sargotrons
8 Replies

9. Shell Programming and Scripting

Get maximum per column from CSV file, based on date column

Hello everyone, I am using ksh on Solaris 10 and I'm gathering data in a CSV file that looks like this: 20170628-23:25:01,1,0,0,1,1,1,1,55,55,1 20170628-23:30:01,1,0,0,1,1,1,1,56,56,1 20170628-23:35:00,1,0,0,1,1,2,1,57,57,2 20170628-23:40:00,1,0,0,1,1,1,1,58,58,2... (6 Replies)
Discussion started by: ejianu
6 Replies

10. UNIX for Beginners Questions & Answers

Awk/sed summation of one column based on some entry in first column

Hi All , I am having an input file as stated below Input file 6 ddk/djhdj/djhdj/Q 10 0.5 dhd/jdjd.djd.nd/QB 01 0.5 hdhd/jd/jd/jdj/Q 10 0.5 512 hd/hdh/gdh/Q 01 0.5 jdjd/jd/ud/j/QB 10 0.5 HD/jsj/djd/Q 01 0.5 71 hdh/jjd/dj/jd/Q 10 0.5 ... (5 Replies)
Discussion started by: kshitij
5 Replies
Test::Valgrind::Action::Test(3pm)			User Contributed Perl Documentation			 Test::Valgrind::Action::Test(3pm)

NAME
Test::Valgrind::Action::Test - Test that an analysis didn't generate any error report. VERSION
Version 1.13 DESCRIPTION
This action uses "Test::Builder" to plan and pass or fail tests according to the reports received. METHODS
This class inherits Test::Valgrind::Action and Test::Valgrind::Action::Captor. "new diag => $diag, extra_tests => $extra_tests, ..." Your usual constructor. When $diag is true, the original output of the command and the error reports are intermixed as diagnostics. $extra_tests specifies how many extraneous tests you want to plan in addition to the default ones. Other arguments are passed straight to "Test::Valgrind::Action->new". "diag" Read-only accessor for the "diag" option. "kinds" Returns the list of all the monitored report kinds. SEE ALSO
Test::Valgrind, Test::Valgrind::Action. AUTHOR
Vincent Pit, "<perl at profvince.com>", <http://www.profvince.com>. You can contact me by mail or on "irc.perl.org" (vincent). BUGS
Please report any bugs or feature requests to "bug-test-valgrind at rt.cpan.org", or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Valgrind <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Valgrind>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. SUPPORT
You can find documentation for this module with the perldoc command. perldoc Test::Valgrind::Action::Test COPYRIGHT &; LICENSE Copyright 2009,2010,2011 Vincent Pit, all rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.12.4 2011-08-25 Test::Valgrind::Action::Test(3pm)
All times are GMT -4. The time now is 03:09 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy