![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| AWK split | slarionoff | Shell Programming and Scripting | 10 | 09-09-2009 08:36 AM |
| split -d | vijay_0209 | Shell Programming and Scripting | 1 | 09-30-2008 03:52 AM |
| help with split | Hawks444 | Shell Programming and Scripting | 1 | 02-28-2008 06:11 PM |
| Split a file with no pattern -- Split, Csplit, Awk | madhunk | UNIX for Dummies Questions & Answers | 10 | 12-17-2007 12:57 PM |
| Split | AkumaTay | UNIX for Dummies Questions & Answers | 1 | 08-18-2001 08:50 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Guys Following input line is from /etc/group file.As we know last entry in a line of /etc/group is userlist (all the users belonging to that group). I need to splilt this one line into 3 lines as shown below (3 because userlist has 3 names in it). Code:
Input: lp:!:11:root,lp,printq Output: lp<TAB>!<TAB>11<TAB>root lp<TAB>!<TAB>11<TAB>lp lp<TAB>!<TAB>11<TAB>printq This way i need to do for all the entries in /etc/group. I need code lines to achive it. Help Appreciated !! Regards Abhi Last edited by ak835; 10-02-2009 at 08:00 AM.. |
|
||||
|
Code:
awk '
{
split($0,A,":");
split(A[4],UL,",");
for (U in UL) {print A[1] "\t" A[2] "\t" A[3] "\t" UL[u]}
}' /etc/group
You probably meant "achieve" iso "achive". Help is not always appreciated. ;-) |
|
||||
|
Thanks for the replies guys. Code:
<Myhost>:$ C='lp:!:11:root,lp,printq'
<Myhost>:$ echo $C
lp:!:11:root,lp,printq
<Myhost>:$ echo $C > c
<Myhost>:$ cat c
lp:!:11:root,lp,printq
<Myhost>:$ awk '
> {
> split($0,A,":");
> split(A[4],UL,",");
> for (U in UL) {print A[1] "\t" A[2] "\t" A[3] "\t" UL[u]}
> }' c
lp ! 11
lp ! 11
lp ! 11
this is not giving me what i want. Regards Abhi |
|
||||
|
Quote:
Code:
for (U in UL) {print A[1] "\t" A[2] "\t" A[3] "\t" UL[u]}
U should be in upper case in UL[U] Last edited by sagar_evc; 10-05-2009 at 11:38 AM.. Reason: u in square brackets is always shown as lower case u |
|
||||
|
yup...i shud have seen that...thanks...!! even i tried writing something ,though its not giving me entirely what i want.. Code:
cat /etc/group | nawk '
{
TUP = split($0, field, ":");
USERS = split(field[4],user, ",");
if (USERS == 0) printf "%s\t%s\t%s\n", field[1], field[3], "NULL";
for (i = 1; i <= USERS; i++)
printf "%s\t%s\t%s\n", field[1], field[3], user[i];
}
'
I m just setting NULL wherever userlist if NULL. Can someone tell me how do i split the row by removing ':' from it into just a row with n columns Code:
lp:!:11:root,lp,printq into Code:
lp ! 11 root,lp,printq such that i can just pick column values using 'awk'. Regards Abhi ---------- Post updated at 02:25 PM ---------- Previous update was at 02:02 PM ---------- okay...this might be it... Code:
bash-3.00$ D='lp:!:11:root,lp,printq'
bash-3.00$ echo $D |sed 's/:/ /g'
lp ! 11 root,lp,printq
bash-3.00$ echo $D |sed 's/:/ /g'|awk '{print $1}'
lp
bash-3.00$ echo $D |sed 's/:/ /g'|awk '{print $2}'
!
bash-3.00$ echo $D |sed 's/:/ /g'|awk '{print $3}'
11
bash-3.00$ echo $D |sed 's/:/ /g'|awk '{print $4}'
root,lp,printq
Regards Abhi ---------- Post updated at 02:39 PM ---------- Previous update was at 02:25 PM ---------- now this one is from /etc/passwd file Code:
abhi:!:34971:3418:abhi k, Sys Admin Level 3:/home/users/abhi:/bin/ksh As we can see,in comments section i have put something against my user id. using the same code above pasted Code:
bash-3.00$ echo $D|sed 's/:/ /g'|awk '{print $5 $6 $7 $8 $9 $10}'
abhik,SysAdminLevel3
I want "abhi k ,Sys Admin Level 3" to be put in just one column as it is (no space deletion).Rest columns are easy to get. Any ideas ? Regards Abhi ---------- Post updated at 03:48 PM ---------- Previous update was at 02:39 PM ---------- i thought this wud work...but it isn't....anything missing? Code:
bash-3.00$ echo $D|sed 's/:/ /g'|awk -F' ' '{$1=$2=$3=$4="";sub("^ ","");print}'
abhi k, Sys Admin Level 3 /home/users/abhi/ /bin/ksh
i just need "abhi k, Sys Admin Level 3"..... Regards Abhi ---------- Post updated at 04:12 PM ---------- Previous update was at 03:48 PM ---------- Code:
bash-3.00$ echo $D|sed 's/:/ /g'|awk -F' ' '{$1=$2=$3=$4="";sub("^ ","");print}'|cut -d "/" -f1
abhi k, Sys Admin Level 3
i hope i am not sounding crazy here.... Regards Abhi |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|