- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: formate text file
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2003 04:42 AM
06-20-2003 04:42 AM
I have a text file something like this,
--------------------
host1
host1-status
host2
host2-status
host3
host4-status
...
.. runs in to several 100 similar lines ...
---------------------
Now I want to format this file to like the following,
-------
host1 host1-status
host2 host2-status
host3 host3-status
------
can I do this using sed or someother command??
Thanks
karthik
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2003 04:47 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2003 04:48 AM
06-20-2003 04:48 AM
Re: formate text file
A simple shell solution :
#!/usr/bin/sh
while read A
do
read B
echo $A $B
done < file
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2003 04:50 AM
06-20-2003 04:50 AM
Re: formate text file
Try this script:
#!/bin/sh
grep 'status$' your_input_file > /tmp/file2
grep -v -f /tmp/file2 your_input_file > /tmp/file1
paste file1 file2 > /tmp/result.txt
Hai
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2003 04:52 AM
06-20-2003 04:52 AM
Re: formate text file
Please change the last line to:
paste /tmp/file1 /tmp/file2 > /tmp/result.txt
Hai
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2003 04:53 AM
06-20-2003 04:53 AM
Re: formate text file
This cuold help:
cont=1
while read i
do
if [ $cont = 1 ];then
a1=$i
let cont=$cont+1
continue
fi
a2=$i
echo "$a1 $a2">>prueba1
cont=1
done
HTH, Vicente.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2003 04:59 AM
06-20-2003 04:59 AM
Re: formate text file
And with sed :
sed '{
N
s/\n/ /
}' file
Regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2003 05:05 AM
06-20-2003 05:05 AM
Re: formate text file
awk '{ printf "%s ",$0 ; getline ; print}' file
Regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2003 05:08 AM
06-20-2003 05:08 AM
Re: formate text file
Thanks a lot for your responses. I ashamed that I never came across the paste command being a Unix Admin so long ... :-(
But I am still in trouble,
My actual file looks like this,
-----------------------------------------------
t3wg-01:/:<2>id read u1pcu1
Battery Life Used : 7 days, 15 hours
t3wg-01:/:<3>id read u1pcu2
Battery Life Used : 7 days, 15 hours
t3wg-02:/:<2>id read u1pcu1
Battery Life Used : 156 days, 22 hours
t3wg-02:/:<3>id read u1pcu2
Battery Life Used : 475 days, 22 hours
t3wg-03:/:<2>id read u1pcu1
Battery Life Used : 654 days, 3 hours
t3wg-03:/:<3>id read u1pcu2
Battery Life Used : 93 days, 5 hours
-----------------------------------------------
Now when I do
paste -s -d"\t\n" textfile
the o/p comes like this,
-----------------------------------------------
t3Battery Life Used : 7 days, 15 hours
t3Battery Life Used : 7 days, 15 hours
t3Battery Life Used : 156 days, 22 hours
t3Battery Life Used : 475 days, 22 hours
t3Battery Life Used : 654 days, 3 hours
t3Battery Life Used : 93 days, 5 hours
t3Battery Life Used : 654 days, 3 hours
t3Battery Life Used : 93 days, 5 hours
test2-t3Battery Life Used : 93 days, 5 hours
----------------------------------------------
that is the first line of every pair is not pasted/displayed fully .. what could be the problem??
Thanks
Karthik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2003 05:11 AM
06-20-2003 05:11 AM
Re: formate text file
Your awk command only prints the second line :-(
Karthik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2003 05:31 AM
06-20-2003 05:31 AM
Re: formate text file
i think hte problem can be in the <> sign.
I will have same tests and then tell you what i find.
Massimo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2003 05:33 AM
06-20-2003 05:33 AM
Re: formate text file
cat test.input | paste -s -d"\t\n" -
where test.input is your file.
It worked for me :)
Massimo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2003 05:35 AM
06-20-2003 05:35 AM
Re: formate text file
Strange ... I tested it before writing !
awk '{ printf "%s ",$0 ; getline ; print}' file
printf "%s ",$0 print current line without LF
getline gets next line
print prints the whole second line including LF
It still works for me ... Like the paste command in fact ... So I'm wondering if your file couldn't contain control characters ?
Regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2003 05:37 AM
06-20-2003 05:37 AM
Re: formate text file
# paste -s -d"\t\n" filename
...works fine for me. Do:
# cat -etc filename
...beforehand to see if you have any special characters embedded (?).
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2003 05:38 AM
06-20-2003 05:38 AM
Re: formate text file
I did a cut&paste of your output, so i think there may be some hidden control character.
Try with
cat -tve yourfile
and let's see what is there !!
Massimo