Sponsored Content
Full Discussion: awk spitting columns
Top Forums UNIX for Beginners Questions & Answers awk spitting columns Post 302995696 by Don Cragun on Monday 10th of April 2017 08:59:40 PM
Old 04-10-2017
There is no need for cat in this pipeline and there is no need for two of your three invocations of awk.

There is no occurrence of the string +2 in your sample input and there is nothing wrong with your calculation as long as the leading character in hour field in your input file is a plus sign. But, your calculation would be wrong if the leading character in that field was a minus sign (which does not appear in your sample input). If we assume that the 1st character in the hour field will ALWAYS either be a plus sign (+) or a minus sign (-), the following seems to do what I would guess you were trying to do:
Code:
awk '{	printf("%s %-15s %-10s %-10s %-6s\n",
	    NR, $1, $2 * 15 + $3 / 4 + $4 / 240,
	    (substr($5, 1, 1) == "-" ? -1 : 1) * \
		(substr($5, 2) + $6 / 60 + $7 / 3600),
	    $8)
}' maser_neg_test.txt > maser_neg_test2.txt

If we add a couple of timestamps with negative hours to your sample maser_neg_test.txt for testing:
Code:
RXSJ00001+0523   00 00 11.78  +05 23 17.4  11992  2016-02-12   51.3   3  10.9  10631  13365
    KUG2358+330   00 00 58.10  +33 20 38.0  12921  2012-11-17   36.5   8   4.0  11461  14395
0001233+4733537   00 01 23.30  +47 33 53.7   5237  2010-11-02   39.5  10   3.6   3848   6639   3.5   6358   9196
       NGC-7805   00 01 26.76  +31 26 01.4   4850  2006-01-05   43.8   5   6.0   3464   6248   5.6   5968   8799
extra	2 3 4 -05 59 60 8 9 10 11 12 13 14 15 16 17
extra2	2 3 4 -10 30 00 8 9 10 11 12 13 14 15 16 17

the above code produces the following output in maser_neg_test2.txt:
Code:
1 RXSJ00001+0523  0.0490833  5.38817    11992 
2 KUG2358+330     0.242083   33.3439    12921 
3 0001233+4733537 0.347083   47.5649    5237  
4 NGC-7805        0.3615     31.4337    4850  
5 extra           30.7667    -6         8     
6 extra2          30.7667    -10.5      8

which I assume is appropriate output for that input.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk sum columns

can anyone help me how do i add the colums using awk seperated by character @. for eg i have 3@4 2@9 5@1 the result should be 10 14 i tried using { sum+= $1 } END { print sum } but it just gives the result 10. can anyone help me with this one thank you and best regards (7 Replies)
Discussion started by: phone_book
7 Replies

2. Shell Programming and Scripting

How to format columns using AWK

Hi, How to format something like this: John Roberts 324-141-984 Acct Jack Williams 159-555-555 Acct William Jackson 949-911-888 Acct Mark J Walton 145-852-252 Acct Fred P Milton 483-244-390 Acct Bill P J Miller 404-050-223 Acct into... (12 Replies)
Discussion started by: ora_umair
12 Replies

3. Shell Programming and Scripting

how to AWK columns from $1 to $5 without $2 $3 $4

hello cant find a way to make something like: awk '{print $1 - $5}' somefile which is printing $1 $2 $3 $4 $5 should make an array or something? i just dont wanna write $1 $2 $3 $4 $5 to awk input i need to use from $1 to $5 and print them all and then i need to swith to: from $6 to $10 (3 Replies)
Discussion started by: tip78
3 Replies

4. UNIX for Dummies Questions & Answers

Using awk to get columns from different files

How can I use awk to create a new file that has 2 columns, each colums comes form a different file. example: I need column 3 from file1 and column 5 from file2 to make file3. (3 Replies)
Discussion started by: cosmologist
3 Replies

5. Shell Programming and Scripting

Awk - New Line between columns

I have a data file with 4 columns, of the format: A1 A2 A3 A4 B1 B2 B3 B4 C1 C2 C3 C4 etc.. I would like to insert to put column 2,3,4 on a new line so my new format would be: A1 A2 A3 A4 B1 B2 B3 B4 C1 C2 C3 C4 etc. but am new at using AWK and am not sure how to do it. (5 Replies)
Discussion started by: mikeyd
5 Replies

6. Shell Programming and Scripting

Removing columns using awk

HI , I have a comma delimiter file, in which I want to remove 8th and 9th column. I tried removing those columns using the below code awk 'BEGIN { FS=","; OFS="," } {$8=$9="";gsub(",+",",",$0)}1' infile But the problem is 8th and 9th columns are user entered fields, theyvhave carriage... (1 Reply)
Discussion started by: mora
1 Replies

7. Shell Programming and Scripting

Rearranging into new columns (awk?)

Hi experts, I've used several solutions from this forum to delete nonsense and rearrange data in the project file I'm working on. I'm hoping you guys can give me some tips on further rearranging the data (I've seen a few solutions by searching, but one specific item has me stumped, which is only... (5 Replies)
Discussion started by: coryvp
5 Replies

8. Shell Programming and Scripting

Gnuplot spitting junk to CL, saying file not found

Hi, I am making a shell script in bash which uses gnuplot to plot the number of road accidents on a certain day, on a certain month. I believe I have the data correct. An example of my data file is here: cat Day1Accidents.txt 01 13 02 5 03 17 04 8 05 16 06 18 07 12 08 7 09 23 10 12... (2 Replies)
Discussion started by: 06s23
2 Replies

9. Shell Programming and Scripting

Sum of columns using awk

Hello everyone I am a beginner in Shell scripting. Need your help to achieve desired result. I have a file (sample format below) 001g8aX0007jxLz xxxxxxxxxxxxxxx 9213974926411 CO-COMM-133 CO-L001-DLY 7769995578239 44938 1 1 ... (1 Reply)
Discussion started by: Rohit Mallah
1 Replies

10. UNIX for Beginners Questions & Answers

How to use "awk" to print columns from different files in separate columns?

Hi, I'm trying to copy and paste the sixth column from a bunch of files into a single file having each column pasted in separate columns (and not one after each other in just one column.) I tried this code but works only partially because it copied and pasted 50 rows of each column... (6 Replies)
Discussion started by: Frastra
6 Replies
unix2dos(1)						      General Commands Manual						       unix2dos(1)

NAME
unix2dos - UNIX to DOS text file format converter SYNOPSYS
unix2dos [options] [-c convmode] [-o file ...] [-n infile outfile ...] Options: [-hkqV] [--help] [--keepdate] [--quiet] [--version] DESCRIPTION
This manual page documents unix2dos, the program that converts text files in UNIX format to DOS format. OPTIONS
The following options are available: -h --help Print online help. -k --keepdate Keep the date stamp of output file same as input file. -q --quiet Quiet mode. Suppress all warning and messages. -V --version Prints version information. -c --convmode convmode Sets conversion mode. Simulates unix2dos under SunOS. -o --oldfile file ... Old file mode. Convert the file and write output to it. The program default to run in this mode. Wildcard names may be used. -n --newfile infile outfile ... New file mode. Convert the infile and write output to outfile. File names must be given in pairs and wildcard names should NOT be used or you WILL lost your files. EXAMPLES
Get input from stdin and write output to stdout. unix2dos Convert and replace a.txt. Convert and replace b.txt. unix2dos a.txt b.txt unix2dos -o a.txt b.txt Convert and replace a.txt in ASCII conversion mode. Convert and replace b.txt in ISO conversion mode. unix2dos a.txt -c iso b.txt unix2dos -c ascii a.txt -c iso b.txt Convert and replace a.txt while keeping original date stamp. unix2dos -k a.txt unix2dos -k -o a.txt Convert a.txt and write to e.txt. unix2dos -n a.txt e.txt Convert a.txt and write to e.txt, keep date stamp of e.txt same as a.txt. unix2dos -k -n a.txt e.txt Convert and replace a.txt. Convert b.txt and write to e.txt. unix2dos a.txt -n b.txt e.txt unix2dos -o a.txt -n b.txt e.txt Convert c.txt and write to e.txt. Convert and replace a.txt. Convert and replace b.txt. Convert d.txt and write to f.txt. unix2dos -n c.txt e.txt -o a.txt b.txt -n d.txt f.txt DIAGNOSTICS
BUGS
The program does not work properly under MSDOS in stdio processing mode. If you know why is that so, please tell me. AUTHOR
Benjamin Lin - ( blin@socs.uts.edu.au ) MISCELLANY
Tested environment: Linux 1.2.0 with GNU C 2.5.8 SunOS 4.1.3 with GNU C 2.6.3 MS-DOS 6.20 with Borland C++ 4.02 Suggestions and bug reports are welcome. SEE ALSO
dos2unix(1) 1995.03.31 unix2dos v2.2 unix2dos(1)
All times are GMT -4. The time now is 10:28 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy