Sponsored Content
Full Discussion: GAWK removes FS | on output
Top Forums UNIX for Advanced & Expert Users GAWK removes FS | on output Post 302360290 by paulr211 on Thursday 8th of October 2009 02:23:55 PM
Old 10-08-2009
GAWK removes FS | on output

I have the simple gawk script below. When the script runs in the output of all the ITM lines the FS is replaced with a space, the Non ITM lines retain the | field separator.

The ITM lines have many fields and I can't insert "|" between each field because some of the fields are blank.

Is there a simple way of keeping the FS?

Thanks,

Paul

# parse.awk -- script to substitute a field
BEGIN { FS="|";rs=nl;
}
{


if ($1=="ITM" && $5=="DIM" )
{
$5 = $25

}

print

}
END {
}

---------- Post updated at 01:23 PM ---------- Previous update was at 12:48 PM ----------

I needed to specify OFS="|"

Last edited by paulr211; 10-08-2009 at 03:16 PM..
This User Gave Thanks to paulr211 For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script removes itself

I have a script that reads from a file and deletes all files in tha path specified in the file.The problem,however, is the script also deletes itself from the home directory where I run it :-( #!/bin/ksh while read DAYS PURGE_PATH do cd $PURGE_PATH find . \( -type d ! -name . -prune \)... (5 Replies)
Discussion started by: kayarsenal
5 Replies

2. UNIX for Dummies Questions & Answers

eval removes backslash

Hi, ============= In one of my config files, I have below command eval echo RECORDDELIMITER '\n' The above command results in removing backslash and outputs: RECORDDELIMITER n ============= Any workaround to retain the backslash after eval. Appreciated for your... (10 Replies)
Discussion started by: axes
10 Replies

3. Ubuntu

Aptitude removes all packages

Hi Team, Please find below error. I got this after i done something in aptitude. Actually i was trying to update all packages, but unfortunately I removed all packages. Now my server is down. When i boot it gives me me errors of missing .so files. Is there any way to repair my server... (2 Replies)
Discussion started by: paragnehete
2 Replies

4. Shell Programming and Scripting

Gawk output difference

Why the below option2 doesn't fetch similar output as option1 ? I am on linux. $cat test 2013-01-01-00.25.43.643845 Option1: cat test | gawk -F"-" ' {print $2 " " $3 " " $1}' 01 01 2013 Option2: cat test | gawk '{FS="-"} {print $2 " " $3 " " $1}' 2013-01-01-00.25.43.643845 (5 Replies)
Discussion started by: Shivdatta
5 Replies

5. Shell Programming and Scripting

Sed: removes \ from text which causes issues

Hi all, Hoping someone hoping someone might be able to help. i've got the following sed command which i'm using in a bash script that i'm trying to use to insert a new line into an already existing file so i don't have to manually enter it when setting stuff up. the existing script test2/3 are... (3 Replies)
Discussion started by: springs2
3 Replies

6. Shell Programming and Scripting

Trying to learn to use functions in gawk and not getting expected output.

I've been working on improving my awk, and the next thing I want to learn is to properly use functions (I understand functions in shell and python). I have the following code which includes how I did this without functions before, and two attempts I've made to do it with functions: function... (3 Replies)
Discussion started by: DeCoTwc
3 Replies

7. UNIX for Dummies Questions & Answers

Why awk removes delimiters?

Code : echo "1,2,3,4"|awk -F "," 'NR==n{$3=a}1' n=1 a=45 Output : 1 2 45 4 Expected : 1,2,45,4 (4 Replies)
Discussion started by: Rajesh_us
4 Replies

8. Shell Programming and Scripting

Gawk output separated by tab

In the gawk below, I am trying to output the file tab-deliminated but don't think that is the correct syntax. Thank you :). gawk OFS='/t' '{sub(/-+/,"",$2); ar=$0} END{n = asort(ar) for (i = 1; i <= n; i++) print ar}' file (2 Replies)
Discussion started by: cmccabe
2 Replies

9. Shell Programming and Scripting

awk removes delimiter unexpectedly

datafile: blah,blah,blah,blah,blah,blah,blah,blah,blah=0_nblah=0-- ,blah,blah,blah im using the following command to turn the "_n" and "-- " to just a space " " only in the $9th field. meaning, it has to make the changes only in the 9th column/field of the datafile. awk -F, '{... (1 Reply)
Discussion started by: SkySmart
1 Replies

10. Shell Programming and Scripting

Gawk --- produce the output in pattern space instead of END space

hi, I'm trying to calculate IP addresses and their respective calls to our apache Server. The standard format of the input is HOST IP DATE/TIME - - "GET/POST reuest" "User Agent" HOST IP DATE/TIME - - "GET/POST reuest" "User Agent" HOST IP DATE/TIME - - "GET/POST reuest" "User Agent" HOST... (2 Replies)
Discussion started by: busyboy
2 Replies
JOIN(1) 						      General Commands Manual							   JOIN(1)

NAME
join - relational database operator SYNOPSIS
join [ options ] file1 file2 DESCRIPTION
Join forms, on the standard output, a join of the two relations specified by the lines of file1 and file2. If one of the file names is the standard input is used. File1 and file2 must be sorted in increasing ASCII collating sequence on the fields on which they are to be joined, normally the first in each line. There is one line in the output for each pair of lines in file1 and file2 that have identical join fields. The output line normally con- sists of the common field, then the rest of the line from file1, then the rest of the line from file2. Input fields are normally separated spaces or tabs; output fields by space. In this case, multiple separators count as one, and leading separators are discarded. The following options are recognized, with POSIX syntax. -a n In addition to the normal output, produce a line for each unpairable line in file n, where n is 1 or 2. -v n Like -a, omitting output for paired lines. -e s Replace empty output fields by string s. -1 m -2 m Join on the mth field of file1 or file2. -jn m Archaic equivalent for -n m. -ofields Each output line comprises the designated fields. The comma-separated field designators are either 0, meaning the join field, or have the form n.m, where n is a file number and m is a field number. Archaic usage allows separate arguments for field designators. -tc Use character c as the only separator (tab character) on input and output. Every appearance of c in a line is significant. EXAMPLES
sort /adm/users | join -t: -a 1 -e "" - bdays Add birthdays to password information, leaving unknown birthdays empty. The layout of is given in users(6); bdays contains sorted lines like tr : ' ' </adm/users | sort -k 3 3 >temp join -1 3 -2 3 -o 1.1,2.1 temp temp | awk '$1 < $2' Print all pairs of users with identical userids. SOURCE
/sys/src/cmd/join.c SEE ALSO
sort(1), comm(1), awk(1) BUGS
With default field separation, the collating sequence is that of sort -b -ky,y; with -t, the sequence is that of sort -tx -ky,y. One of the files must be randomly accessible. JOIN(1)
All times are GMT -4. The time now is 05:29 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy