Sponsored Content
Top Forums Shell Programming and Scripting AWK swapping fields on different lines Post 302624341 by itkamaraj on Monday 16th of April 2012 06:40:17 AM
Old 04-16-2012
Code:
 
$ nawk '{a=$1;b=$0;getline;c=$2" "$3;sub(c,a);sub(a,c,b);printf("%s\n%s",b,$0)}' test.txt
Mr. Smith Cyclist 10:59 #(newline here)
Cyclist Andrew has a great track record....
 
$ cat test.txt 
Andrew Cyclist 10:59 #(newline here)
Cyclist Mr. Smith has a great track record....

This User Gave Thanks to itkamaraj For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Swapping lines beginning with certain words using sed/awk

I have a large file which reads like this: fixed-address 192.168.6.6 { hardware ethernet 00:22:64:5b:db:b1; host X; } fixed-address 192.168.6.7 { hardware ethernet 00:22:64:5b:db:b3; host Y; } fixed-address 192.168.6.8 { hardware ethernet 00:22:64:5b:db:b4; host A; }... (4 Replies)
Discussion started by: ksk
4 Replies

2. Shell Programming and Scripting

Swapping of fields in a file

Hi I have afile with 15fields,say f1,f2....f15 delimited on comma. How can i swap the f1,f15 fields using unix shell commands or any script? Thanks (3 Replies)
Discussion started by: ksailesh
3 Replies

3. Shell Programming and Scripting

How to (n)awk lines of CSV with certain number of fields?

I have a CSV file with a variable number of fields per record. How do I print lines of a certain number of fields only? Several permutations of the following (including the use of escape characters) have failed to retrieve the line I'm after (1,2,3,4)... $ cat myfile 1,2,3,4 1,2,3 $ # Print... (1 Reply)
Discussion started by: cs03dmj
1 Replies

4. Homework & Coursework Questions

Swapping Fields with Sed

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: The assignment is to convert a text table to csv format. I've got the cleaning up done, but I need to swap two... (0 Replies)
Discussion started by: VoiceInADesert
0 Replies

5. Shell Programming and Scripting

awk - use fields from subsequent lines

I've run into a problem getting exactly what I want out of awk - some folks may recognize this as an output from Amazon's ec2-describe-instances: Given the following: INSTANCE i-4960f321 BLOCKDEVICE Line2Var2 TAG instance i-4960f321 Name web1 TAG instance i-4960f321... (2 Replies)
Discussion started by: colinjohnson
2 Replies

6. Shell Programming and Scripting

Swapping of fields in file

Hi Friends , I have file1.txt 1|b|46|123|47673|348738 2|c|63|124|7346|4783 3|y|45|125|5555|78789 output should swap the 4th field to the first field. output 123|1|b|46|47673|348738 124|2|c|63|7346|4783 125|3|y|45|5555|78789 (3 Replies)
Discussion started by: i150371485
3 Replies

7. Shell Programming and Scripting

select lines with certain values on certain fields with awk

I need a awk command to select from a log-file only the lines that have on the 2nd field (considering "|" separator) one of the values 10.216.22.XX or 10.216.22.YY or 10.216.22.ZZ and on the 4th field only values that contain strictly digits. I want the command to work parsing the file only once (I... (2 Replies)
Discussion started by: black_fender
2 Replies

8. Shell Programming and Scripting

Swapping fields

Hallo Team, This is the command that i am running : grep ",Call Forward Not Reachable" *2013* this is the output that i am getting (i did a head -10 but the files can be more than 1000) ... (8 Replies)
Discussion started by: kekanap
8 Replies

9. Shell Programming and Scripting

Swapping/replacing fields

Hallo Team, I would like to replace filed 4 and 7 with filed 39 how can i achieve this ? -bash-3.2$ cat dip1.csv| cut -f4,7,24,36,39 -d","|sort -u +27113996891,+27113996891,196.35.130.52,828854047,+27873500077 +27116452690,+27825702918,10.0.109.13:5060,+27116452690,+27116452690... (2 Replies)
Discussion started by: kekanap
2 Replies

10. Shell Programming and Scripting

awk to combine lines if fields match in lines

In the awk below, what I am attempting to do is check each line in the tab-delimeted input, which has ~20 lines in it, for a keyword SVTYPE=Fusion. If the keyword is found I am splitting $3 using the . (dot) and reading the portion before and after the dot in an array a. If it does have that... (12 Replies)
Discussion started by: cmccabe
12 Replies
GMTLIST(1gmt)						       Generic Mapping Tools						     GMTLIST(1gmt)

NAME
gmtlist - A data-extractor for <legid>.gmt files SYNOPSIS
gmtlist leg-ids [ -Ccorrectionfile ] [ -Dastartdate ] [ -Dbstopdate ] [ -Fflags ] [ -G ] [ -H[i][nrec] ] [ -Rwest/east/south/north[r] ] [ -Sastartdist ] [ -Sbstopdist ] [ -V ] [ -Wweight ] [ -bo[s|S|d|D[ncol]|c[var1/...]] ] DESCRIPTION
gmtlist reads <legid>.gmt files and produces an ASCII [or binary] table. The <legid>.gmt files contain time(s), latitude(y), longitude(x), gravity(g/G), magnetics(m/M), and bathymetry(t/T), and the user may extract any combination of these 6 parameters + distance(d), heading (h), velocity (v), and weight (w, see -W). A sub-section can be specified by passing time- or distance-intervals along track or by select- ing a region. leg-ids Can be one or more cruisenames. To give a list of names, use `cat list_of_legs`. OPTIONS
No space between the option flag and the associated arguments -C Apply crossover Corrections to the data. If no correction file is given, gmtlist reads the default correction file. (See XSYSTEM for how to set up your own correction file). -Da Do not list data collected before startdate (mm/dd/yyyy/hh:mm) [Default is first day]. -Db Do not list data collected after stopdate (mm/dd/yyyy/hh:mm). [Default is last day]. -F Can be any combination of syxgmtdhv to indicate the desired output data. The data will appear in the order indicated by flags. If G, M, or T is substituted for g, m, t, only records that have that combination of data are written out. If s is followed by c (calen- dar), then yyyy/mm/dd/hh/mm/ss is written out, if s is followed by j (julian), then yyyy/jd/hh/mm/ss is written out. Default is seconds from start of year. -G Force Geographical longitudes (-180/+180) rather than geodetic (0-360) [Default]. -H Issue a header record with names for each data field. -R west, east, south, and north specify the Region of interest, and you may specify them in decimal degrees or in [+-]dd:mm[:ss.xxx][W|E|S|N] format. Append r if lower left and upper right map coordinates are given instead of w/e/s/n. The two shorthands -Rg and -Rd stand for global domain (0/360 and -180/+180 in longitude respectively, with -90/+90 in latitude). Alterna- tively, specify the name of an existing grid file and the -R settings (and grid spacing, if applicable) are copied from the grid. -Sa Do not list data that are less than startdist km along track from port of departure. [Default is 0]. -Sb Do not list data that are more than stopdist km along track from port of departure. [Default is length of track]. -V Selects verbose mode, which will send progress reports to stderr [Default runs "silently"]. -W Set the weight for these data. Weight output option must be set in -F. This is useful if the data are to be processed with the weighted averaging techniques offered by blockmean, blockmedian, and blockmode. -b Selects binary output mode (in double precision) [Default is ASCII]. -H is ignored if -b is selected. Julian and calendar dates are not supported for binary time output (i.e., you get seconds from start of year). EXAMPLES
To get a (distance, heading, crossover-corrected gravity, bathymetry) listing from c2104.gmt, starting at June 3 1971 20:45 and ending at distance = 5000 km, use the following command: gmtlist c2104 -Da6/3/1971/20:45 -Sb5000 -Fdhgt -C > myfile To make input for blockmean and surface using all the cruises listed in the file gmt.list, but only the data that are inside the specified area, and make output binary: gmtlist `cat gmt.list` -Fxyg -R-40/-30/25/35 -b > allgrav.xyg SEE ALSO
GMT(1), x_system(1) REFERENCES
Wessel, P., and W. H. F. Smith, 2011, The Generic Mapping Tools (GMT) version 4.5.7 Technical Reference & Cookbook, SOEST/NOAA. Wessel, P., and W. H. F. Smith, 1998, New, Improved Version of Generic Mapping Tools Released, EOS Trans., AGU, 79(47), p. 579. Wessel, P., and W. H. F. Smith, 1995, New Version of the Generic Mapping Tools Released, EOS Trans., AGU, 76(33), p. 329. Wessel, P., and W. H. F. Smith, 1995, New Version of the Generic Mapping Tools Released, http://www.agu.org/eos_elec/95154e.html, Copyright 1995 by the American Geophysical Union. Wessel, P., and W. H. F. Smith, 1991, Free Software Helps Map and Display Data, EOS Trans., AGU, 72(41), p. 441. GMT 4.5.7 15 Jul 2011 GMTLIST(1gmt)
All times are GMT -4. The time now is 09:10 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy