Sponsored Content
Full Discussion: awk line extraction question
Top Forums Shell Programming and Scripting awk line extraction question Post 302413578 by jazthedribbler on Friday 16th of April 2010 09:15:23 AM
Old 04-16-2010
awk line extraction question

Hi,

I am trying to extract the first and last lines for each unique item in column 2 of a large text file and then concatenate all extracted lines together in a new text file.

So ... I want to go from this format:

Code:
NEW 0088-BPM 1.042700e+04 877168.19 9718360.00 1496.00
NEW 0088-BPM 1.042800e+04 877143.31 9718359.00 1497.00
NEW 0088-BPM 1.042900e+04 877093.50 9718358.00 1501.00
NEW 0088-BPM 1.042900e+04 877081.06 9718358.00 1502.00
NEW 0088-BPM 1.043000e+04 877056.12 9718358.00 1503.00
NEW 0088-BPM 1.043000e+04 877043.69 9718358.00 1504.00
NEW 0088-BPM 1.043100e+04 877031.25 9718358.00 1505.00
NEW 7493-BPM 4.890000e+03 681176.38 9977126.00 11514.00
NEW 7493-BPM 4.891000e+03 681178.19 9977141.00 11515.00
NEW 7493-BPM 4.892000e+03 681210.62 9977179.00 11519.00
NEW 7493-BPM 4.892000e+03 681220.19 9977187.00 11520.00
NEW 7493-BPM 4.893000e+03 681223.94 9977201.00 11521.00
NEW 7493-BPM 4.893000e+03 681233.50 9977209.00 11522.00
NEW 7493-BPM 4.893000e+03 681243.00 9977217.00 11523.00
......

to this format:
Code:
NEW 0088-BPM 1.042700e+04 877168.19 9718360.00 1496.00
NEW 0088-BPM 1.043100e+04 877031.25 9718358.00 1505.00
NEW 7493-BPM 4.890000e+03 681176.38 9977126.00 11514.00
NEW 7493-BPM 4.893000e+03 681243.00 9977217.00 11523.00
......

Probably very simple!

Thanks,

jazthedribbler

Last edited by Scott; 04-16-2010 at 11:46 AM.. Reason: Please use code tags
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

SED scipt help - line extraction

Forgive me if this is a dumb question...I'm a Windows sys admin with little programming knowledge. I have files containing anywhere from 3 to 200 lines. Using SED, I want to extract only lines containing a specific instance of "ISS." It is possible that "ISS" will occur several times in a... (10 Replies)
Discussion started by: thuston22
10 Replies

2. Shell Programming and Scripting

AWK extraction

Hi all, Can anyone please help me in parsing the following file. Suppose the file is called, example.lst, and has the following content in it. (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP) (Host = 192.168.2.2) ... (3 Replies)
Discussion started by: harris2107
3 Replies

3. Shell Programming and Scripting

AWK end of line question

Any clues on how to parse a line returned from an ls command that allows for the filename to be fully passed even if it includes spaces? What I got close with is: ls -ltra | awk '{print $1 "|" $3 "|" $4 "|" $5 "|" $6 "|" $7 "|" $8 "|" $9 $10 $11 $12 ... (etc)}' However this clears the spaces in... (6 Replies)
Discussion started by: jpport123
6 Replies

4. Shell Programming and Scripting

AWK extraction

Hi all, I have a data file from which i would like to extract only certain fields, which are not adjacent to each other. Following is the format of data file (data.txt) that i have, which has about 6 fields delimited by "|" HARRIS|23|IT|PROGRAMMER|CHICAGO|EMP JOHN|35|IT|JAVA|NY|CON... (2 Replies)
Discussion started by: harris2107
2 Replies

5. Shell Programming and Scripting

extraction of last but one char in a line

I need to extract the character before the last "|" in the following lines, which are 'N' and 'U'. The last "|" shouldn't be extracted. Also the no.s of "|" may vary in a line, but I need only the character before the last one. ... (1 Reply)
Discussion started by: hidnana
1 Replies

6. Shell Programming and Scripting

Another data extraction question

Hi, I have a tmp file like below: <ADATA> ANUM=900 ADESC=Saving ATYP=0 TXREGD=0 </ADATA> <ADATA> ANUM=890 ADESC=Saving ATYP=0 ABAL=9000 TXREGD=1 </ADATA> <ADATA> (6 Replies)
Discussion started by: kunigirib
6 Replies

7. Shell Programming and Scripting

File extraction without awk

Hello everybody, Here is my problem : I cannot find a way to extract data from a particular file and more precisely I cannot extract the result of my awk script to an external file because I am currently working on HP-UX. I would like a simple script (without awk) which asks for a date like... (4 Replies)
Discussion started by: freyr
4 Replies

8. Shell Programming and Scripting

awk :quick question removing empty line.

How to write in awk to remove lines starting with "#" and then process the file: This is not working: cat file|awk '{if ($0 ~ /^#/) $0="";print NF>0}' When I just give cat file|awk '{if ($0 ~ /^#/) $0="";print }' it prints the blank lines . I don't wnat the blank lines along with the... (15 Replies)
Discussion started by: rveri
15 Replies

9. Shell Programming and Scripting

Multi line extraction based on condition

Hi I have some data in a file as below ****************************** Class 1A Students absent are : 1. ABC 2. CDE 3. CPE ****************************** Class 2A Students absent are : ****************************** Class 3A Students absent are : (6 Replies)
Discussion started by: reldb
6 Replies
IGAWK(1)							 Utility Commands							  IGAWK(1)

NAME
igawk - gawk with include files SYNOPSIS
igawk [ all gawk options ] -f program-file [ -- ] file ... igawk [ all gawk options ] [ -- ] program-text file ... DESCRIPTION
Igawk is a simple shell script that adds the ability to have ``include files'' to gawk(1). AWK programs for igawk are the same as for gawk, except that, in addition, you may have lines like @include getopt.awk in your program to include the file getopt.awk from either the current directory or one of the other directories in the search path. OPTIONS
See gawk(1) for a full description of the AWK language and the options that gawk supports. EXAMPLES
cat << EOF > test.awk @include getopt.awk BEGIN { while (getopt(ARGC, ARGV, "am:q") != -1) ... } EOF igawk -f test.awk SEE ALSO
gawk(1) Effective AWK Programming, Edition 1.0, published by the Free Software Foundation, 1995. AUTHOR
Arnold Robbins (arnold@skeeve.com). Free Software Foundation Nov 3 1999 IGAWK(1)
All times are GMT -4. The time now is 08:37 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy