Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Help selecting some rows with awk Post 302352475 by capnino on Friday 11th of September 2009 12:22:11 PM
Old 09-11-2009
Help selecting some rows with awk

Hi there, I have a text file with several colums separated by "|;#" I need to search the file extracting all columns starting with the value of "1" or "2" saving in a separate file just the first 7 columns of each row maching the criteria, with replacement of the saparators in the nearly created file from "|;#" into ";".
Just for instance this is what I have :
Code:
1;Paul;10|100;20090909#2000;1000;40;20;100;80;1000;500
2;Lara;10|100;20090909#2100;2000;80;40;100;80;1000;500
1;Carlos;24|100;20090909#2200;4000;30;50;100;80;1000;500
4;Juan;12|100;20090909#2010;6000;20;20;600;80;1000;500
3;Chis;18|100;20090909#2001;8000;50;20;100;80;1000;500

What I need in a separate file is this :
Code:
1;Paul;10;100;20090909;2000;1000
2;Lara;10;100;20090909;2100;2000
1;Carlos;24;100;20090909;2200;4000

Thanks a lot in advance for your help
Nino

Last edited by vbe; 09-11-2009 at 01:31 PM.. Reason: code tags added
 

10 More Discussions You Might Find Interesting

1. Programming

selecting rows with specific IDs for downstream analysis

Hi, I'm working hard on SQL and I came across a hurdle I'm hoping you can help me out with. I have two tables table1 headers: chrom start end name score strand 11 9720685 9720721 U0 0 + 21 9721043 9721079 U0 0 - 1 9721093 9721129 U0 0 + 20 ... (2 Replies)
Discussion started by: labrazil
2 Replies

2. UNIX for Dummies Questions & Answers

Awk ranges for selecting numbers

Hi, I am trying to use AWK to do some editing and formating of large tables of numbers and I am having trouble getting it to work. For brevities sake, I won't show the whole table, but I have a sample set of code: und$ awk '{($2+0) > 50;print $1}' temp 2000 147 2008 128 2002 100 1999 47... (2 Replies)
Discussion started by: ikerrin1@gmail.
2 Replies

3. Shell Programming and Scripting

Selecting rows with a specific criteria

Hi, I want a UNIX command that can filter out rows with certain criteria. The file is tab deliminated. Row one is just a value. Basically what I want to do is select based on the name and character at the end (o). So lets lets say i want a row that has WashU and (o) then it would print... (2 Replies)
Discussion started by: phil_heath
2 Replies

4. UNIX for Dummies Questions & Answers

Selecting specific line using awk

Hi, I would like to get the specific line from the file taking specific coloumn as reference. Thanks and Regards (1 Reply)
Discussion started by: kkarthik_kaja
1 Replies

5. Shell Programming and Scripting

selecting lines using awk

I have a file which contains five hundred thousand lines (500,000). I want to select lines of every 1000 lines from that file using AWK. I can think something like this in bash as below: for lines in {0..500000..1000} do ........ ........ done But I want to use AWK. I do not know how to... (4 Replies)
Discussion started by: vjramana
4 Replies

6. Shell Programming and Scripting

Selecting rows based on values in columns

Hi My pipe delimited .txt file contains rows with 10 columns. Can anyone advise how I output to file only those rows with the letters ‘ci' as the first 2 characters in the 3rd column ? Many thanks (4 Replies)
Discussion started by: malts18
4 Replies

7. UNIX for Dummies Questions & Answers

Removing duplicate rows & selecting only latest date

Gurus, From a file I need to remove duplicate rows based on the first column data but also we need to consider a date column where we need to keep the latest date (13th column). Ex: Input File: Output File: I know how to take out the duplicates but I couldn't figure out... (5 Replies)
Discussion started by: shash
5 Replies

8. Shell Programming and Scripting

Selecting rows from a pipe delimited file based on condition

HI all, I have a simple challenge for you.. I have the following pipe delimited file 2345|98|1809||x|969|0 2345|98|0809||y|0|537 2345|97|9809||x|544|0 2345|97|0909||y|0|651 9685|98|7809||x|321|0 9685|98|7909||y|0|357 9685|98|7809||x|687|0 9685|98|0809||y|0|234 2315|98|0809||x|564|0 ... (2 Replies)
Discussion started by: nithins007
2 Replies

9. Shell Programming and Scripting

Help with shell script: selecting rows that have the same values in two columns

Hello, everyone I am beginner for shell programming. I want to print all lines that have the same values in first two columns data: a b 1 2 a a 3 4 b b 5 6 a b 4 6 what I expected is : a a 3 4 b b 5 6 but I searched for one hour in... (2 Replies)
Discussion started by: nengcheng
2 Replies

10. Shell Programming and Scripting

Size Selecting rows

I have a rather convoluted script that I use to extract information from CSV files: sed '1d' PeakTable.txt | awk -F ',' '!/Ladder/{ if ( $4 > 430 && $4 < 490 && $5 > 45 ) print $2, $5; else print $2, 0 }' | awk '{a+=$2}END{for(i in a){print i, a}}' | sed 's/\(\)\(\) /\10\2 /' | sort | awk... (4 Replies)
Discussion started by: Xterra
4 Replies
DBLINK_FETCH(3) 					  PostgreSQL 9.2.7 Documentation					   DBLINK_FETCH(3)

NAME
dblink_fetch - returns rows from an open cursor in a remote database SYNOPSIS
dblink_fetch(text cursorname, int howmany [, bool fail_on_error]) returns setof record dblink_fetch(text connname, text cursorname, int howmany [, bool fail_on_error]) returns setof record DESCRIPTION
dblink_fetch fetches rows from a cursor previously established by dblink_open. ARGUMENTS
conname Name of the connection to use; omit this parameter to use the unnamed connection. cursorname The name of the cursor to fetch from. howmany The maximum number of rows to retrieve. The next howmany rows are fetched, starting at the current cursor position, moving forward. Once the cursor has reached its end, no more rows are produced. fail_on_error If true (the default when omitted) then an error thrown on the remote side of the connection causes an error to also be thrown locally. If false, the remote error is locally reported as a NOTICE, and the function returns no rows. RETURN VALUE
The function returns the row(s) fetched from the cursor. To use this function, you will need to specify the expected set of columns, as previously discussed for dblink. NOTES
On a mismatch between the number of return columns specified in the FROM clause, and the actual number of columns returned by the remote cursor, an error will be thrown. In this event, the remote cursor is still advanced by as many rows as it would have been if the error had not occurred. The same is true for any other error occurring in the local query after the remote FETCH has been done. EXAMPLES
SELECT dblink_connect('dbname=postgres'); dblink_connect ---------------- OK (1 row) SELECT dblink_open('foo', 'select proname, prosrc from pg_proc where proname like ''bytea%'''); dblink_open ------------- OK (1 row) SELECT * FROM dblink_fetch('foo', 5) AS (funcname name, source text); funcname | source ----------+---------- byteacat | byteacat byteacmp | byteacmp byteaeq | byteaeq byteage | byteage byteagt | byteagt (5 rows) SELECT * FROM dblink_fetch('foo', 5) AS (funcname name, source text); funcname | source -----------+----------- byteain | byteain byteale | byteale bytealike | bytealike bytealt | bytealt byteane | byteane (5 rows) SELECT * FROM dblink_fetch('foo', 5) AS (funcname name, source text); funcname | source ------------+------------ byteanlike | byteanlike byteaout | byteaout (2 rows) SELECT * FROM dblink_fetch('foo', 5) AS (funcname name, source text); funcname | source ----------+-------- (0 rows) PostgreSQL 9.2.7 2014-02-17 DBLINK_FETCH(3)
All times are GMT -4. The time now is 03:27 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy