Cut data and put it in next line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cut data and put it in next line
# 1  
Old 03-24-2008
Cut data and put it in next line

here is my sample file

dn: cn=Anandmohan Singh,ou=addressbook,dc=thbs,dc=com
objectClass: top
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
cn: Anandmohan Singh
givenName: Anandmohan
mail: anand_ms@thbs.com
mobile: 9986010455
ou: null
physicalDeliveryOfficeName: ST-6th Floor
sn: Singh
telephoneNumber: 41827200 Extn: 7400
title: Associate Software Engineer - Trainee
uid: 1432

dn: cn=Riteshkumar Mohanty,ou=addressbook,dc=thbs,dc=com
objectClass: top
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
cn: Riteshkumar Mohanty
givenName: Riteshkumar
mail: ritesh_m@thbs.com
mobile: 9916953109
ou: null
physicalDeliveryOfficeName: ST-6th Floor
sn: Mohanty
telephoneNumber: 41827200 Extn: 7400
title: Associate Software Engineer - Trainee
uid: 1418

i want to cut the ext from the line where telephone number is given and put it in next line,something like this--

dn: cn=Anandmohan Singh,ou=addressbook,dc=thbs,dc=com
objectClass: top
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
cn: Anandmohan Singh
givenName: Anandmohan
mail: anand_ms@thbs.com
mobile: 9986010455
ou: null
physicalDeliveryOfficeName: ST-6th Floor
sn: Singh
telephoneNumber: 41827200
Extn: 7400
title: Associate Software Engineer - Trainee
uid: 1432

dn: cn=Riteshkumar Mohanty,ou=addressbook,dc=thbs,dc=com
objectClass: top
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
cn: Riteshkumar Mohanty
givenName: Riteshkumar
mail: ritesh_m@thbs.com
mobile: 9916953109
ou: null
physicalDeliveryOfficeName: ST-6th Floor
sn: Mohanty
telephoneNumber: 41827200
Extn: 7401
title: Associate Software Engineer - Trainee
uid: 1418
# 2  
Old 03-24-2008
If you put your file content in a file called "hi.txt" then his is the command to obtain what you required:

[ramki@lindesk3 ramki]$ cat hi.txt | grep -i "ext"
telephoneNumber: 41827200 Extn: 7400

[ramki@lindesk3 ramki]$ cat hi.txt | grep -i "ext" | sed 's/ Extn/\nExtn/g'
telephoneNumber: 41827200
Extn: 7400

Thanks,
Ramkrix

Last edited by ramkrix; 03-24-2008 at 02:59 AM..
# 3  
Old 03-24-2008
heres a guideline of what i think needs to be done.
have input file hi.txt and outputfile hi2.txt

read each line of input file and output to new file.
on each line do an awk:

eg.

cat hi.txt | awk '{print $1 " " $2 " " $3 " " $4 } '
telephone: 345345435 Extn: 4545

now u have four fields seperate.

then when $1 = "telephone:"
output $1 and $2 then next line
output $3 and $4.

and at the eof
mv hi2.txt to hi.txt
# 4  
Old 03-24-2008
Code:
$ sed -i '/^telephoneNumber:/ s/Extn/\nExtn/' tel.txt

//Jadu
# 5  
Old 03-24-2008
Code:
awk  '{
if($1=="telephoneNumber:" && $3=="Extn:")
printf("%s %s\n %s %s\n",$1,$2,$3,$4)
else
print
}' filename

# 6  
Old 03-24-2008
thanks alot everyone,i got it working.
I appericiate the quick response of you guys.

Thanks...
# 7  
Old 03-25-2008
Hope This should work

grep "Extn:" filename | awk '{printf("%s%s\n",$1,$2);printf("%s%s\n",$3,$4)}'


Regards,
aajan
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

AIX put comma separated data on its own line

In Linux you can do this to put comma separated data on its own line like this. sed 's/ */&\n/g' /tmp/ports sed 's/ */\n/g' /tmp/ports How do you do this in AIX? It is not working. Is there another way to do this? Something like this. 1, 2, 3, 4 To look like this. 1 2 3 4 (4 Replies)
Discussion started by: cokedude
4 Replies

2. Shell Programming and Scripting

Put delimeter in data based on value

Hi Friends, I have a file as below source.txt 12345JackYKing32N 1235 JulyYoig 31N i am using cut command for cutting the fields cut -c 1-5 source.txt 12345 1235 like above i have to use each time to cut all the fieds manually. I have a file(pre.txt) which tells... (3 Replies)
Discussion started by: i150371485
3 Replies

3. Shell Programming and Scripting

sed or awk, cut, to extract specific data from line

Hi guys, I have been trying to do this, but... no luck so maybe you can help me. I have a line like this: Total Handled, Received, on queue Input Mgs: 140 / 14 => 0 I need to, get the number after the / until the =, to get only 14 . Any help is greatly appreciated. Thanks, (4 Replies)
Discussion started by: ocramas
4 Replies

4. Shell Programming and Scripting

Match word and put data before it

Hi all I have 7 words ina file called "lookupfile" CAD CD HT RA T1D T2D BD in other file I have data like this in which columns are seaprated by comma but the names among above seven names are in one column menas comma between these seven words doesnt mean that they are separated by... (9 Replies)
Discussion started by: manigrover
9 Replies

5. UNIX for Dummies Questions & Answers

Put data in tabular form..

Dear Friends, I have a file as under : +++ ME 12-06-13 18:16:20 A RED FEW AND ROW1 1MN FEL AS HI FI BV LR TS HR ES MR * 0 13296 0 120 1 15 KS RR 10 0 +++ ME 12-06-13 18:26:20 A RED FEW AND ROW2 1MN FEL AS... (2 Replies)
Discussion started by: vanand420
2 Replies

6. UNIX for Dummies Questions & Answers

Put data into tabular form

Hi I am having a file which is required to be presented in the under-noted output form. Please suggest. Input: Kapil: apple 4 banana 6 cherry 0 Manoj: apple 13 banana cheery 2 Output: apple banana cherry Kapil: 4 6 0 Manoj: 13 2 Thanks in... (4 Replies)
Discussion started by: vanand420
4 Replies

7. Programming

Perl - how to put to the next line if I have same pattern in one line

Dear All, Could you help me how to put to the next line if I have pattern below in Perl language. Data-123 Linux MacOSData-124 windows FreeBSDData-125 OpenBSD NetBSD I would the output below: Data-123 Linux MacOS Data-124 windows FreeBSD Data-125 OpenBSD NetBSD ... (2 Replies)
Discussion started by: askari
2 Replies

8. Shell Programming and Scripting

Remove line based on string and put new line with parameter

Hi Folks, I am new to ksh, i have informatica parameter file that i need to update everyday with shell script. i need your help updating this file with new parameters. sample data $$TABLE1_DATE=04-27-2011 $$TABLE2_DATE=04-23-2011 $$TABLE3_DATE=03-19-2011 .......Highligned... (4 Replies)
Discussion started by: victor369
4 Replies

9. Slackware

How should I cut this line using cut and grep?

not sure how to do it. wan't to delete it using cut and grep ince i would use it in the shell. but how must the command be? grep "64.233.181.103 wwwGoogle.com" /etc/hosts | cut -d the delimeter is just a space. can you help meplease. :D (1 Reply)
Discussion started by: garfish
1 Replies

10. Shell Programming and Scripting

Put raw data to column data

Dear all, I want below data to make it in column format.so i will see the data like this cdrID teleServiceCode chargedPartyNumber ... ... ... ... "egmailcom0w10ggzx00" 'sMS (5)' "716323770" "m17ifi5z30w0z6o7200" 'sMS (5)' ... (7 Replies)
Discussion started by: Nayanajith
7 Replies
Login or Register to Ask a Question