Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Say I have a file which is of following format
Group:
Asd
Bsd
Csd
Owner:
Date:Group:
Aed
Asd
Csd
Owner:
Date:I want
Group: Asd,Bsd,Csd
Owner:
Date:Group: Aed,Asd,Csd
Owner:
Date:How can I do this in Unix. Any suggestion ????
Regards
Arun

You can set up a really ugly break point report in a shell script. When the line equals Group: read each line appending to a variable until the word owner appears. Print the variable and continue the loop:
#!/bin/bash
pr_line=""
g_flag=0
fr=1
while read line
do
if [[ ${line} = "Group:" ]]
then
g_flag=1
pr_line=${line}
continue
fi# print when line equals Owner:
if [[ ${line} = "Owner:" ]]
then
printf "%s\n" ${pr_line}
g_flag=0
fr=1
fiif [[ g_flag -eq 1 ]]
then
if [[ fr -eq 1 ]]
then
pr_line=${pr_line}${line}
fr=0
else
pr_line=${pr_line},${line}
fi
continue
fiprintf "%s\n" ${line}
done < data.file

Below, is the output of the bash script. It looks exactly like what you asked for. If isn't, you need to provide more information about the problem:
Group:Asd,Bsd,Csd
Owner:
Date:Group:Aed,Asd,Csd
Owner:
Date:

Hi Actually My data file is eactly this :
Data file f2.dat :
Data for GROUP 'bin'
Userlist:
bin
daemon
root
scpar
test
Owner: nobody (USER )
Create time: 13-Feb-2007 10:35
Update time: 13-Feb-2007 10:45
Updated by: rootData for GROUP 'console'
Owner: nobody (USER )
Create time: 13-Feb-2007 10:35
Update time: 13-Feb-2007 10:35
Updated by: rootData for GROUP 'daemon'
Userlist:
bin
daemon
root
Owner: nobody (USER )
Create time: 13-Feb-2007 10:35
Update time: 13-Feb-2007 10:45
Updated by: rootSo i want the Userlist as
Userlist:bin,daemon,root,scpar,test
For 2 nd Group (console) no Userlist so dont do anythingUserlist:bin,daemon,root.
Pls advice......
Regards
Arun

Hi I also need all the other data. But i want to Manipulate only UserList so that Userlist is such that
UserList: bin,daemon,root
instead of
UserList:
bin
daemon
root
. All other fields i need no changes....Regards
Arun

You can't expect a break point report to work when you change the data break rules:
#!/bin/bash
pr_line=""
g_flag=0
fr=1
while read line
do
# save when beginning line equals Userlist:
case "${line}" in
Userlist:*)
g_flag=1
pr_line="${line}"
continue
;;
# print when beginning line equals Owner:
Owner:*)
if [[ -n ${pr_line} ]]
then
printf "%s\n" "${pr_line}"
fi
pr_line=""
g_flag=0
fr=1
;;
esacif [[ g_flag -eq 1 ]]
then
if [[ fr -eq 1 ]]
then
pr_line=${pr_line}${line}
fr=0
else
pr_line=${pr_line},${line}
fi
continue
fiprintf "%s\n" "${line}"
done < f2.dat

Hi all
I have a Data in following format which i want to convert to a Flat File.
The Input data is user.dat :
Data: bin
----------------
Userlist: bin,daemon,root,scpar,test
Owner: nobody (USER )
Create time: 13-Feb-2007 10:35
Update time: 13-Feb-2007 10:45
Updated by: rootData: console
----------------
Owner: nobody (USER )
Create time: 13-Feb-2007 10:35
Update time: 13-Feb-2007 10:35
Updated by: rootData: daemon
----------------
Userlist: bin,daemon,root
Owner: nobody (USER )
Create time: 13-Feb-2007 10:35
Update time: 13-Feb-2007 10:45
Updated by: rootData: db2asgrp
----------------
Owner: nobody (USER )
Create time: 13-Feb-2007 10:35
Update time: 13-Feb-2007 10:35
Updated by: rootThe Output file should be :
Data~Userlist~Owner~Create Time~Update time~ updated by that is for Data:bin output should be following. I want to do this for each Data :
bin~bin,daemon,root,scpar,test~nobody (USER )~13-Feb-2007 10:35~13-Feb-2007 10:45~rootIf any field is empty then it must print delimiter ~~ . That is if for data: Console
There is no UserList so output must be
console~~nobody (USER)~13-Feb-2007 10:35~13-Feb-2007 10:35~rootPls advice ...
Regards
Arun

Is this home work? It looks like it to me.
If this is home work, you should be doing it
yourself, and perhaps asking questions to
help you understand what you are trying to
do. If you do not learn to do the work
yourself, how will you do it when you are
out in the real world? If this is not home
work, please do not be offended, after all,
you are asking two similar question now ...Ernie Registered Linux User 247790
ICQ 41060744

Hi Actually from some Users i dont have UsersList. So when i search for each user if there is no UserList it must just print delimiter if u can tell me how i can approach it . It will be of great help for me .
Regards
Arun

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |