Sponsored Content
Top Forums Shell Programming and Scripting Help with txt formatting using AWK Post 302342544 by eknryan on Monday 10th of August 2009 11:38:01 AM
Old 08-10-2009
Thanks Panyam. I think I get it but Ive tried to modify the script to add a further condition but seem to be getting nowhere. I am trying to output as previously however within each series of $1 and $2 values if
Code:
NR=i ; $4=v and NR=i+1 ; $4<v

then I do not want to print anything where NR>=i.

So if input was
Code:
L73-10 342 0 1480
L73-10 342 100 1480
L73-10 342 250 1656
L73-10 342 500 1500
L73-10 342 750 1910
L73-10 350 0 1480
L73-10 350 100 1480
L73-10 350 250 1656
L73-11 300 0 1480
L73-11 300 100 1480
L73-11 300 250 1656
L73-11 300 500 1546


Only a formatted version of the following would be output

Code:
L73-10 342 0 1480
L73-10 342 100 1480
L73-10 342 250 1656
L73-10 350 0 1480
L73-10 350 100 1480
L73-10 350 250 1656
L73-11 300 0 1480
L73-11 300 100 1480
L73-11 300 250 1656

Can anybody help me out?

Thanks again
Ryan

---------- Post updated at 10:38 AM ---------- Previous update was at 06:28 AM ----------

I know this wont exclude all lines beyond a reversed $4 value but can anyone tell me what is wrong with this?

Code:
BEGIN { s=0;t=0;NR=i;vel=$4 } NR==FNR { if($2==s&&$1==t) { a[$1]=a[$1]","$3"-"$4;t=$1;s=$2 } else { a[$1]=a[$1]"/"$2":"$3"-"$4;t=$1;s=$2 }}
END {if(NR==i+1&&vel>$4) {for ( i in a ) { print i a[i]"/"} }}

Also, is there any way of adding standard $3 $4 values say $3=6000 and $4=4500 to the end of every unique $1$2 set?

I hope ive explained this reasonably. Im a geophysicist with no experience of programming. I seem to spend hours trying variation after variation of code and have been trawing unix.com and google but seem to get lost all too often. Any help really would be appreciated!
Thanks
Ryan

Last edited by eknryan; 08-10-2009 at 09:37 AM.. Reason: Poorly explained problem
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Formatting using awk

Let's say I write a simple script that contains the following: date | awk '{print $1}' date | awk '{print $2}' Of course, when I run the script the output will look similar to: Tue Mar What if I want my ouput to be on one line as follows: Tue Mar What changes would I need to... (2 Replies)
Discussion started by: cdunavent
2 Replies

2. UNIX for Dummies Questions & Answers

echo "ABC" > file1.txt file2.txt file3.txt

Hi Guru's, I need to create 3 files with the contents "ABC" using single command. Iam using: echo "ABC" > file1.txt file2.txt file3.txt the above command is not working. pls help me... With Regards / Ganapati (4 Replies)
Discussion started by: ganapati
4 Replies

3. Shell Programming and Scripting

AWK CSV to TXT format, TXT file not in a correct column format

HI guys, I have created a script to read 1 column in a csv file and then place it in text file. However, when i checked out the text file, it is not in a column format... Example: CSV file contains name,age aa,11 bb,22 cc,33 After using awk to get first column TXT file... (1 Reply)
Discussion started by: mdap
1 Replies

4. Shell Programming and Scripting

AWK formatting help.

Dear all I require help with AWK regarding this situation Input is : fn1 12345 fn1 23456 fn3 231513 fn1 22325 fn3 123125 Desired output is fn1 12345 23456 22325 fn3 231513 123125 (5 Replies)
Discussion started by: Peasant
5 Replies

5. Shell Programming and Scripting

formatting awk

when i try this awk its giving out put as below. awk '!(/^$/||/--/||/selected/||/^ *$/){print $1}' tmp.txt output ===== 1 2010-08-03-12.31.26.126000 how excluede the 1st line ? i mean i want output only 2nd line i.e 2010-08-03-12.31.26.126000; (5 Replies)
Discussion started by: rocking77
5 Replies

6. Shell Programming and Scripting

awk append fileA.txt to growing file B.txt

This is appending a column. My question is fairly simple. I have a program generating data in a form like so: 1 20 2 22 3 23 4 12 5 43 For ever iteration I'm generating this data. I have the basic idea with cut -f 2 fileA.txt | paste -d >> FileB.txt ???? I want FileB.txt to grow, and... (4 Replies)
Discussion started by: theawknewbie
4 Replies

7. UNIX for Dummies Questions & Answers

awk formatting

Hi all, I'm writing a simple awk code: awk 'BEGIN {FS="|"};{print "Type\tNumber\ttypes\tTotal";};{print $1, "\t", $2, "\t", $3, "\t", $4, "\t";}' db_query.txt it gives me the result: Type Number types Total XXX 498.0 5100.0 5274.661 Type Number types Total... (7 Replies)
Discussion started by: messi777
7 Replies

8. UNIX for Dummies Questions & Answers

Removing PATTERN from txt without removing lines and general text formatting

Hi Everybody! First post! Totally noobie. I'm using the terminal to read a poorly formatted book. The text file contains, in the middle of paragraphs, hyphenation to split words that are supposed to be on multiple pages. It looks ve -- ry much like this. I was hoping to use grep -v " -- "... (5 Replies)
Discussion started by: AxeHandle
5 Replies

9. Shell Programming and Scripting

Desired output.txt for reading txt file using awk?

Dear all, I have a huge txt file (DATA.txt) with the following content . From this txt file, I want the following output using some shell script. Any help is greatly appreciated. Greetings, emily DATA.txt (snippet of the huge text file) 407202849... (2 Replies)
Discussion started by: emily
2 Replies

10. Shell Programming and Scripting

Awk, sed, shell all words in INPUT.txt find in column1 of TABLE.txt and replce with column2 in

Hi dears i have text file like this: INPUT.txt 001_1_173 j nuh ]az 001_1_174 j ]esma. nuh ]/.xori . . . and have another text like this TABLE.txt j j nuh word1... (6 Replies)
Discussion started by: alii
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:32 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy