Sponsored Content
Full Discussion: OFS in awk
Top Forums UNIX for Dummies Questions & Answers OFS in awk Post 302720065 by MIA651 on Tuesday 23rd of October 2012 12:48:36 PM
Old 10-23-2012
OFS in awk

Hello,

I have an issue with adding commas as delimiters in this scenario:

Code:
cat xtr3.rpl|head -5|awk 'BEGIN {OFS=","} {print $1,$2,$3,$4}'

Produces this output:

00530083,0000000471,000000000000.00,000000000000.00
00530085,0000000471,000000000000.00,000000000000.00
00550002,0000000471,000000000000.00,000000000015.00
00550030,0000000471,000000000000.00-000000000007.99,
00550034,0000000471,000000000000.00,000000000000.00

The problem here is that when there is a negative value in the 4th column it doesn't recognize the 4th column due to the fact there is no space between the 3rd and 4th column (as you can see in the 4th row) when that happens.

Can anyone kindly help me out?

Thanks!
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

OFS in awk

Hi, I have these out put field seperator changed to "|" in my awk command, but it didn't give me the result. Can someone help me find out why? ======================================= /bin/awk 'BEGIN { OFS="|" } { print $0 }' list.tmp.$$ > listtmp.$$ =======================================... (1 Reply)
Discussion started by: whatsfordinner
1 Replies

2. Shell Programming and Scripting

OFS in awk.

OFS is inbuild command in awk. I have a file file.txt abc : def : ghi jkl : mno: pqr stu : vwx :yzz code i used: awk -F ":" 'BEGIN {OFS="|"} {print $1,$2}' file.txt output: abc def jkl mno stu vwx but as i have used OFS="|" and i am expecting output as: abc | def jkl... (4 Replies)
Discussion started by: salil2012
4 Replies

3. Shell Programming and Scripting

AWK - OFS

Hi All, I have a comma seperated delimited file with 10 columns. I need to convert it into TAB seperated delimited file. awk -F"," '{print $1"\t"$2"\t"$3"\t"$4"\t"$5"\t"$6"\t"$7"\t"$8"\t"$9"\t"$10}' a.txt >> b.txt how to use OFS to get the same output. I have tried by googling, but it... (5 Replies)
Discussion started by: Amit.Sagpariya
5 Replies

4. Shell Programming and Scripting

Parsing XML in awk : OFS does not work as expected

Hi, I am trying to parse regular XML file where I have to reduce number of decimal points in some xml elements. I am using following AWK command to achive that : #!/bin/ksh EDITCMD='BEGIN { FS = ""; OFS=FS } { if ( $3 ~ "*\\.*" && length(substr($3,1+index($3,"."))) == 15 ) {... (4 Replies)
Discussion started by: martin.franek
4 Replies

5. UNIX for Dummies Questions & Answers

Problem with AWK and OFS

I have a file that looks like this: Infile.seq I want to output the DNA sequence and add the filename as the identifier. The output file should look like this: I am using the following code but I do not understand why the sequence is not in the output: awk 'BEGIN { RS =... (11 Replies)
Discussion started by: Xterra
11 Replies

6. Shell Programming and Scripting

Awk OFS issues

Hi Im trying to tidy up the output of a who command when it writes to a log, everything I've tried doesnt seem to work though, any help would be massively appreciated. Im using the awk command to set the OFS as tab. #!/bin/bash who >> /export/home/tjmoore/logusers awk -F 'BEGIN... (3 Replies)
Discussion started by: 02JayJay02
3 Replies

7. Shell Programming and Scripting

Awk OFS issues

Hi, Could anyone tell me what Im doing wrong here any help will be much appreciated #!/bin/bash ls -ltr /export/home/tjmoore > /export/home/tjmoore/log100 awk -F " " /export/home/tjmoore/log100 'BEGIN {OFS="\t";} {print $1,$2,$3,$4,$5, $6,$7,$8,$9;}' > /export/home/tjmoore/log1001 I... (9 Replies)
Discussion started by: 02JayJay02
9 Replies

8. Shell Programming and Scripting

OFS print awk

file: sasa|asasa|asasa|asas erer|Erer|rere|ererer Output needed : sasa:asasa:asasa:asas erer:Erer:rere:ererer Im getting output, when i use the $1,$2. awk -F'|' 'BEGIN{OFS=":";} {print $1,$2; }' file Output : sasa:asasa erer:Erer But when i need the whole column, i... (5 Replies)
Discussion started by: Ramesh M
5 Replies

9. Shell Programming and Scripting

OFS does not apply to few records in awk

Hi , I am having a problem with my awk oneliner , which for some reason leaves the first two records Input File $ cat file1 A1:B1:C1:NoLimit M1:M2:M3:Limit A2:B2:C2,C3,C4,C5 A3:B3:C3,C4,C5,C6,C7Desired output A1,B1,C1,NoLimit M1,M2,M3,Limit A2,B2,C2 ,,,C3 ,,,C4 ,,,C5 A3,B3,C3... (5 Replies)
Discussion started by: chidori
5 Replies

10. Shell Programming and Scripting

awk - OFS printing duplicate. Why?

Why the following code printing duplicate records? bash-4.1$ cat rm1 c1 c2 c3 l1 2 3 4 l2 2 3 2 bash-4.1$ awk '{print $0} OFS = "\n"' rm1 c1 c2 c3 c1 c2 c3 l1 2 3 4 l1 2 3... (4 Replies)
Discussion started by: quincyjones
4 Replies
BEASTIE.4TH(8)						    BSD System Manager's Manual 					    BEASTIE.4TH(8)

NAME
beastie.4th -- FreeBSD ASCII art boot module DESCRIPTION
The file that goes by the name of beastie.4th is a set of commands designed to draw the ASCII art FreeBSD mascot -- known simply as beastie -- to the right of the boot loader menu. The commands of beastie.4th by themselves are not enough for most uses. Please refer to the exam- ples below for the most common situations, and to loader(8) for additional commands. Before using any of the commands provided in beastie.4th, it must be included through the command: include beastie.4th This line is present in the default /boot/loader.rc file, so it is not needed (and should not be re-issued) in a normal setup. The commands provided by it are: draw-beastie Draws the FreeBSD logo. The logo that is drawn is configured by setting the loader_logo variable in loader.conf(5) to one of ``beastie'', ``beastiebw'', ``fbsdbw'', ``orb'', and ``orbbw'' (the default). The position of the logo can be configured by setting the loader_logo_x and loader_logo_y variables in loader.conf(5). The default values are 46 (x) and 4 (y). clear-beastie Clears the screen of beastie. beastie-start Initializes the interactive boot loader menu. The loader_delay variable can be configured in loader.conf(5) to the number of seconds you would like to delay loading the boot menu. During the delay the user can press Ctrl-C to fall back to autoboot or ENTER to proceed. The default behavior is to not delay. The environment variables that effect its behavior are: loader_logo Selects the desired logo in the beastie boot menu. Possible values are: ``fbsdbw'', ``beastie'', ``beastiebw'', ``orb'', ``orbbw'' (default), and ``none''. loader_logo_x Sets the desired column position of the logo. Default is 46. loader_logo_y Sets the desired row position of the logo. Default is 4. beastie_disable If set to ``YES'', the beastie boot menu will be skipped. The beastie boot menu is always skipped if booting UEFI or running non-x86 hardware. loader_delay If set to a number higher than zero, introduces a delay before starting the beastie boot menu. During the delay the user can press either Ctrl-C to skip the menu or ENTER to proceed to the menu. The default is to not delay when loading the menu. FILES
/boot/loader The loader(8). /boot/beastie.4th beastie.4th itself. /boot/loader.rc loader(8) bootstrapping script. EXAMPLES
Standard i386 /boot/loader.rc: include /boot/beastie.4th beastie-start Set a different logo in loader.conf(5): loader_logo="beastie" SEE ALSO
loader.conf(5), loader(8), loader.4th(8) HISTORY
The beastie.4th set of commands first appeared in FreeBSD 5.1. AUTHORS
The beastie.4th set of commands was written by Scott Long <scottl@FreeBSD.org>, Aleksander Fafula <alex@fafula.com> and Devin Teske <dteske@FreeBSD.org>. BSD
April 27, 2014 BSD
All times are GMT -4. The time now is 04:37 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy