Sponsored Content
Top Forums Shell Programming and Scripting Split these into many ...(/etc/group)!! Post 302359215 by ak835 on Tuesday 6th of October 2009 06:42:35 AM
Old 10-06-2009
MySQL

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
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Split file by data group

Hi all, I'm having a little trouble solving a file split I need to get done. I have the following data: 1. Light 1A. Light Soft texture: it's soft color: the color value is that of something light vital statistics: srm: 23 og: 1.035 sp: 1.065 comment: this is nice if you like... (8 Replies)
Discussion started by: mkastin
8 Replies

2. Shell Programming and Scripting

split file based on group count

Hi, can some one please help me to split the file based on groups. like in the below scenario x indicates the begining of the group and the file should be split each with 2 groups below there are 10 groups it should create 5 files. could you please help? (4 Replies)
Discussion started by: hitmansilentass
4 Replies

3. Shell Programming and Scripting

Sort the file contents in each group....print the group title as well

I've this file and need to sort the data in each group File would look like this ... cat file1.txt Reason : ABC 12345-0023 32123-5400 32442-5333 Reason : DEF 42523-3453 23345-3311 Reason : HIJ 454553-0001 I would like to sort each group on the last 4 fileds and print them... (11 Replies)
Discussion started by: prash184u
11 Replies

4. Shell Programming and Scripting

Split, Search and Reformat by Data Group

Hi, I am writing just to share my appreciation for help I have received from this site in the past. In a previous post Split File by Data Group I received a lot of help with a troublesome awk script to reformat some complicated data blocks. What I learned really came in hand recently when I... (1 Reply)
Discussion started by: mkastin
1 Replies

5. Shell Programming and Scripting

need a one liner to grep a group info from /etc/group and use that result to search passwd file

/etc/group tiadm::345:mk789,po312,jo343,ju454,ko453,yx879,iy345,hn453 bin::2:root,daemon sys::3:root,bin,adm adm::4:root,daemon uucp::5:root /etc/passwd mk789:x:234:1::/export/home/dummy:/bin/sh po312:x:234:1::/export/home/dummy:/bin/sh ju454:x:234:1::/export/home/dummy:/bin/sh... (6 Replies)
Discussion started by: chidori
6 Replies

6. UNIX for Dummies Questions & Answers

Split binary file every occurrence of a group of characters

Hello I am new to scripts, codes, bash, terminal, etc. I apologize this my be very scattered because I frankly don't have any idea where to begin and I have had trouble sleeping lately. I have several 2GB files I wish to split. This Code 00 00 01 BA ** ** ** ** ** ** ** ** C3 F8 00 00 01 BB 00... (17 Replies)
Discussion started by: PatrickE
17 Replies

7. Programming

Sql ORA-00937: not a single-group group function

I'm trying to return only one row with the highest value for PCT_MAX_USED. Any suggestions? When I add this code, I get the ORA-00937 error. trunc(max(decode( kbytes_max, 0, 0, (kbytes_alloc/kbytes_max)*100))) pct_max_used This is the original and returns all rows. select (select... (3 Replies)
Discussion started by: progkcp
3 Replies

8. Shell Programming and Scripting

ksh : split hex number group

Hi, sry for poor english I have a group of hex number as : 4D40:4D42 I want so split this group in a list as : 4D40,4D41,4D42 i don't know how i can do this in ksh Thanks (5 Replies)
Discussion started by: jocazh
5 Replies

9. Shell Programming and Scripting

Process split files with same name by group

File examples f17_mar_01_02_03_04_fsw1.xml f17_mar_01_02_03_04_fsw2.xml f17_mar_01_02_03_04_fsw3.xml f17_feb_13_20_49_06_fsw1.xml f17_feb_13_20_49_06_fsw2.xml f17_feb_13_20_49_06_fsw3.xml I have many xml files that are grouped with same file name, but are numbered from 1-to-many... (2 Replies)
Discussion started by: aachave1
2 Replies
All times are GMT -4. The time now is 09:15 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy