10-09-2007
awk 2 delimiter nested Problem
Hello All, This work could be very easy for you guys. I would really appreciate help.
input file:
Quote:
aa|bb|cc|dd,ee ff,xx|gg,zz|hh,bv
ii|jj|kk|ll,mm|nn,as|oo,lk
pp|qq|rr|ss,tt uu,yy|vv,xc|ww,mn
output file: (Desired)
Quote:
num=aa value=bb digits=cc name1=dd:link1=ee name2:ff:link2=xx file=gg:link=zz code=hh:link=bv
num=ii value=jj digits=kk name1=ll:link1=mm file=nn:link=as code=oo:link=lk
num=pp value=qq digits=rr name1=ss:link1=tt name2=uu:link2=yy file=vv:link=xc code=ww:link=mn
What I am capable of doing:
Command: cat inputfile | awk -F\| '{print "num="$1" value="$2" digits="$3" name1="$4" file="$5" code="$6}' > outputfile
Result what I am capable of getting:
Quote:
num=aa value=bb digits=cc name1=dd,ee ff,xx file=gg,zz code=hh,bv
num=ii value=jj digits=kk name1=ll,mm file=nn,as code=oo,lk
num=pp value=qq digits=rr name1=ss,tt uu,yy file=vv,xc code=ww,mn
As per my understanding some tricks to that command is needed to involve nested 2 delimiters (i.e. "|" & "," & " "(space) chracter). I dont have any idea how to go about it. Could anyone solve this thing for me or give me some diff logic to acheive this desired output file.
I would really appreciate if some one helps as soon as poss. Thanks a lot people.
Last edited by onlyroshni; 10-09-2007 at 07:54 PM..
10 More Discussions You Might Find Interesting
1. UNIX for Advanced & Expert Users
Hey all,
Can I put sed command inside the awk action ?? If not then can i do grep in the awk action ??
For ex:
awk '$1=="174" { ppid=($2) ; sed -n '/$ppid/p' tempfind.txt ; }' tempfind.txt
Assume: 174 is string.
Assume: tempfind.txt is used for awk and sed both.
tempfind.txt... (11 Replies)
Discussion started by: varungupta
11 Replies
2. Shell Programming and Scripting
Hello - is there any way in awk I can do...
4861 x(1) y(1) z(1)
4959 x(1) y(1) z(1)
5007 x(1) y(1) z(1)
4861 x(2) y(2) z(2)
4959 x(2) y(2) z(2)
5007 x(2) y(2) z(2)
4861 x(3) y(3) z(3)
4959 x(3) y(3) z(3)
5007 x(3) y(3) z(3)
to become...
4861 x(1) y(1) z(1) 4861 x(2) y(2) z(2)... (3 Replies)
Discussion started by: catwoman
3 Replies
3. Shell Programming and Scripting
Hi Friends.
Please have a look at dummy file. I need to extract from this file:
1. Counts of event=
2. the 2nd coulmn is unique call id of this transaction. Based on that, i have to search for txstatus= .
Note: Values of event, calltype and txstatus can be anything.
I want to print... (1 Reply)
Discussion started by: itsmesanju
1 Replies
4. Shell Programming and Scripting
Hello all,
I am writing up an input file and I was hoping I could get some guidance as to how to best consolidate these 2 awk statements for 1 while loop.
Here's my input file
# cat databases.lst
#NOTE: These entries are delimited by tabs "\t"
#oracleSID name/pass
#
db11 ... (2 Replies)
Discussion started by: Keepcase
2 Replies
5. Shell Programming and Scripting
please let me know if the below code could be written efficiently inside single awk
case "$INP" in
ksh)
cat catalog | awk 'BEGIN {FS=",";} { print $2 } END {}'
;;
pset)
cat catalog | awk 'BEGIN {FS=",";} { print $3 } END {}'
;;
dml)
cat catalog | awk 'BEGIN {FS=",";} {... (2 Replies)
Discussion started by: cvsanthosh
2 Replies
6. Shell Programming and Scripting
Folks - newbie bash coder here and I'd like to get your help to make the code below work. As you can see, I was trying to count the total number of lines with the 3rd value >= 15 in a file and wanted to make the threshold "15" configurable, but apparently the $THRESHOLD value was not populated... (3 Replies)
Discussion started by: bashzipper
3 Replies
7. Shell Programming and Scripting
Hello again everyone,
yes, I'm back again for more help! So I'm attempting to read two separate files and generate some XML code from that. My current code is:
BEGIN {
print "<?xml version=\"1.0\" encoding=\"utf-8\">"
print "<Export>"
}
{
x=1;
print "<section name=\"Query" NR "\">"... (5 Replies)
Discussion started by: Parrakarry
5 Replies
8. Shell Programming and Scripting
Hi Gurus,
I have a command to assign value based on input value.
current condition is "if pattern matches "case", then assign "HOLD" else "SUCC"right now, I need to add one more condition (variable name is VAR).
the condition is "if pattern1 matches "case", then assign "HOLD" else if... (2 Replies)
Discussion started by: ken6503
2 Replies
9. Shell Programming and Scripting
I am trying to parse a text file and send its output to another file but I am having trouble conceptualizing how I am supposed to do this in awk.
The text file has a organization like so:
Name
Date
Status
Location (city, state, zip fields)
Where each of these is on a separate line in... (1 Reply)
Discussion started by: kellyanneghj
1 Replies
10. Shell Programming and Scripting
Hello.
I would like to convert the following piece of code from bash to awk.
Here are bash variables in a bash script.
CUR_ROW_ID and ROW_ID_TO_SEARCH contains a string which represent a row id.
The string contain a valid row id.
CUR_ROW_ID sometimes may be null.
CUR_VALUE... (3 Replies)
Discussion started by: jcdole
3 Replies
LEARN ABOUT NETBSD
linkat
LINK(2) BSD System Calls Manual LINK(2)
NAME
link -- make a hard file link
LIBRARY
Standard C Library (libc, -lc)
SYNOPSIS
#include <unistd.h>
int
link(const char *name1, const char *name2);
int
linkat(int fd1, const char *name1, int fd2, const char *name2, int flags);
DESCRIPTION
The link() function call atomically creates the specified directory entry (hard link) name2 with the attributes of the underlying object
pointed at by name1. If the link is successful: the link count of the underlying object is incremented; name1 and name2 share equal access
and rights to the underlying object.
If name1 is removed, the file name2 is not deleted and the link count of the underlying object is decremented.
name1 must exist for the hard link to succeed and both name1 and name2 must be in the same file system. name1 may not be a directory unless
the caller is the super-user and the file system containing it supports linking to directories.
When operating on a symlink, link() resolves the symlink and creates a hard link on the target. linkat() will do the same if
AT_SYMLINK_FOLLOW is set in flags, but it will link on the symlink itself if the flag is clear.
At the moment, linkat() is partially implemented. It will return ENOSYS for fd1 and fd2 values different than AT_FDCWD.
RETURN VALUES
Upon successful completion, a value of 0 is returned. Otherwise, a value of -1 is returned and errno is set to indicate the error.
ERRORS
link() will fail and no link will be created if:
[EACCES] A component of either path prefix denies search permission, or the requested link requires writing in a directory with a
mode that denies write permission.
[EDQUOT] The directory in which the entry for the new link is being placed cannot be extended because the user's quota of disk
blocks on the file system containing the directory has been exhausted.
[EEXIST] The link named by name2 does exist.
[EFAULT] One of the pathnames specified is outside the process's allocated address space.
[EIO] An I/O error occurred while reading from or writing to the file system to make the directory entry.
[ELOOP] Too many symbolic links were encountered in translating one of the pathnames.
[EMLINK] The link count of the file named by name1 would exceed {LINK_MAX}.
[ENAMETOOLONG] A component of a pathname exceeded {NAME_MAX} characters, or an entire path name exceeded {PATH_MAX} characters.
[ENOENT] A component of either path prefix does not exist, or the file named by name1 does not exist.
[ENOSPC] The directory in which the entry for the new link is being placed cannot be extended because there is no space left on the
file system containing the directory.
[ENOTDIR] A component of either path prefix is not a directory.
[EOPNOTSUPP] The file system containing the file named by name1 does not support links.
[EPERM] The file named by name1 is a directory and the effective user ID is not super-user, or the file system containing the file
does not permit the use of link() on a directory.
[EROFS] The requested link requires writing in a directory on a read-only file system.
[EXDEV] The link named by name2 and the file named by name1 are on different file systems.
SEE ALSO
symlink(2), unlink(2)
STANDARDS
The link() function conforms to ISO/IEC 9945-1:1990 (``POSIX.1'').
BUGS
linkat() is partially implemented.
BSD
January 12, 1994 BSD