Split these into many ...(/etc/group)!!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Split these into many ...(/etc/group)!!
# 8  
Old 10-12-2009
MySQL

Thanks !! but i did not understand what important info....


even with awk -F':' ' , i m getting same result...

Code:
bash-3.00$ D='abhi:!:34971:3418:abhi k, Sys Admin Level 3:/home/users/abhi:/bin/ksh'
bash-3.00$ echo $D|awk -F':' '{$1=$2=$3=$4="";sub("^    ","");print}'
abhi k, Sys Admin Level 3 /home/users/abhi /bin/ksh
bash-3.00$ echo $D|awk -F':' '{$1=$2=$3=$4="";sub("^    ","");print}'|cut -d "/" -f1
abhi k, Sys Admin Level 3

would appreciate if you can point-out !!

Regards
Abhi
# 9  
Old 10-19-2009
awk -F ':' '{print $5}' /etc/passwd
# 10  
Old 10-20-2009
Error

okay...

now i badly need advice...

I have a fingerprinting tool thru which i generate a lot of data in CSVs.

I need all of information in /etc/group file.

lets say,i want to get following line in my CSV.My requirement here is bit tricky.I want 2 separate entries in CSV for following line.

Code:
bin:!:2:root,bin

should look like

bin 2 root
bin 2 bin

now this is how i have written command lines in my fingerprinting tool:

Code:
ParentFamily : Host etcGroup

GroupName:

cat /etc/group |awk '{print $1}' | cut -d ":" -f1

GID

A=`cat /etc/group | awk -F':' '{if ($1 == "@@Host etcGroup.GroupName@@" ) print $3}'`
echo $A

UserList

A=`cat /etc/group | awk -F':' '{if ($1 == "@@Host etcGroup.GroupName@@" ) print $4}'`

B=`echo $A|wc -w`

C=`echo $A|grep "\,"|wc -l`

D=`echo $A|awk -F',' '{ print NF }'`

if [ $B = 0 ]
then
echo NULL
fi

if [ $B = 1 ]
then
   if [ $C = 0 ]
   then
   echo $A
   else
   XXXXXXX
   XXXXXXX
fi
fi

As you can see,i am stuck at 'XXXXXX' place.I am not sure what to write there to get what is required .

Regards
Abhi
# 11  
Old 10-20-2009
Code:
# echo 'bin:!:2:root,bin' | awk -F'[:|,]' 'END{for(i=3;++i<=NF;)print $1,$3,$i}'
bin 2 root
bin 2 bin

You are not stuck, just make your life complicated.
# 12  
Old 10-20-2009
Bug

well...thanks for this !!

Code:
echo 'bin:!:2:root,bin' | awk -F'[:|,]' 'END{for(i=3;++i<=NF;)print $1,$3,$i}'
bin 2 root
bin 2 bin

but the fingerprinting engine does not work this way.I have defined 3 columns totally ,'GroupName' being first and am fetching 'GroupName' in next 2columns.

whatever data i want to see in CSV,tool has to generate it...its a complicated thing ....can't help it !!

to get something like 'bin:!:2:root,bin' before passing to 'awk',i need to write additonal lines and even after it may not work.

I'll try this and would post my update.

Regards
Abhi
# 13  
Old 10-26-2009
This problem has been dealt with in a different thread, recently.
# 14  
Old 10-27-2009
MySQL

Can you point me to that thread pls?

By the way,i found solution to my issue...i divided my code into parent-child relationship and wrote following lines for child fingerprint....the 'while' loop is not mine..i took it from very this forum....

Code:
A=`cat /etc/group | awk -F':' '{if ($1 == "@@Host etcGroup.GroupName@@" ) print $4}'`

B=`echo $A|wc -w`

if [ $B = 0 ]
then
echo NULL
else
count=`echo $A| nawk -F, {'print NF'}`
i=1
while [ $i -le $count ]
do
str[$i]=`echo $A| cut -d, -f${i}`
echo "${str[$i]}"
i=`expr $i + 1`
done
fi

Thanks to everyone who responded !!

Regards
Abhi
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

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. 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

7. 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

8. 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

9. 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
Login or Register to Ask a Question