03-13-2013
From GNU AWK manual
Understanding $0
It is important to remember that $0 is the full record, exactly as it was read from the input. This includes any leading or trailing whitespace, and the exact whitespace (or other characters) that separate the fields.
It is a not-uncommon error to try to change the field separators in a record simply by setting FS and OFS, and then expecting a plain ‘print’ or ‘print $0’ to print the modified record.
But this does not work, since nothing was done to change the record itself. Instead, you must force the record to be rebuilt, typically with a statement such as ‘$1 = $1’, as described earlier.
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
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 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
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
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
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
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
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. UNIX for Dummies Questions & Answers
Hello,
I have an issue with adding commas as delimiters in this scenario:
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... (10 Replies)
Discussion started by: MIA651
10 Replies
9. Shell Programming and Scripting
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
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
fwtmp(1M) fwtmp(1M)
NAME
fwtmp, wtmpfix - manipulate connect accounting records
SYNOPSIS
[files]
DESCRIPTION
fwtmp
reads from the standard input and writes to the standard output, converting binary records of the type found in to formatted ASCII records.
The ASCII version is useful to enable editing, via ed(1), bad records or for general purpose maintenance of the file.
The argument is used to denote that input is in ASCII form, and output is to be written in binary form. The arguments and are independent,
respectively specifying ASCII input and binary output. Therefor, is an ASCII to ASCII copy and is a binary to binary copy. should be used
for reading If is not used, structure is read.
wtmpfix
examines the standard input or named files in format, corrects the time/date stamps to make the entries consistent, and writes to the stan-
dard output. A can be used in place of files to indicate the standard input. If time/date corrections are not performed, will fault when
it encounters certain date-change records.
Each time the date is set, a pair of date change records is written to The first record is the old date denoted by the string old time
placed in the line field and the flag placed in the type field of the structure. The second record specifies the new date, and is denoted
by the string placed in the line field and the flag placed in the type field. uses these records to synchronize all time stamps in the
file. nullifies date change records when writing to the standard output by setting the time field of the structure in the old date change
record equal to the time field in the new date change record. This prevents and from factoring in a date change record pair more than
once.
In addition to correcting time/date stamps, wtmpfix checks the validity of the name field to ensure that it consists solely of alphanumeric
characters or spaces. If it encounters a name that is considered invalid, it changes the login name to and writes a diagnostic to the
standard error. This minimizes the risk that will fail when processing connect accounting records.
DIAGNOSTICS
wtmpfix generates the following diagnostics messages:
WARNINGS
generates no errors, even on garbage input.
FILES
SEE ALSO
ed(1), acct(1M), acctcms(1M), acctcom(1M), acctcon(1M), acctmerg(1M), acctprc(1M), acctsh(1M), runacct(1M), acct(2), acct(4), utmp(4),
wtmps(4).
STANDARDS CONFORMANCE
fwtmp(1M)