- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: scripting help required
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
09-14-2002 09:33 PM
09-14-2002 09:33 PM
scripting help required
Could somebody help me with a script that im trying to make. The idea is just reformating data....Example data:
############################
2
1.1 2.2 3.1 4.1 5.1 6.2 7.1
9.1 9.2 9.6 9.8 9.8 8.2 3.4
1.1 2.2 3.1 4.1 5.1 6.2 7.1
1
1.1 2.2 3.1 4.1 5.1 6.2 7.1
9.1 9.2 9.6 9.8 9.8 8.2 3.4
1.1 2.2 3.1 4.1 5.1 6.2 7.1
5
1.1 2.2 3.1 4.1 5.1 6.2 7.1
9.1 9.2 9.6 9.8 9.8 8.2 3.4
1.1 2.2 3.1 4.1 5.1 6.2 7.1
############################
The script should be able to go through the file and check for all lines containing 1 field and make all the associated data in to one row.
for example in this case for the first part:
2 1.1 2.2 3.1 4.1 5.1 6.2 1.1
9.1 9.2 9.6 9.8 9.8 8.2 3.4 1.1 2.2 3.1 4.1 5.1 6.2 7.1
Thanks in advance
Soji
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2002 10:55 PM
09-14-2002 10:55 PM
Re: scripting help required
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2002 12:16 AM
09-15-2002 12:16 AM
Re: scripting help required
Here is a quick script for your purpose,
=====Begin
#!/bin/ksh
cat
do
if [ "$LINE" = "`echo $LINE | awk '{print $1}'`" ]
then
echo $NEWLINE
NEWLINE=$LINE
else
NEWLINE=$NEWLINE" "$LINE
fi
done
echo $NEWLINE
======End
Regards,
Patrick
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2002 07:17 AM
09-15-2002 07:17 AM
Re: scripting help required
Perhaps this is what you need. Call it for example txt1 and use it "txt1
#!/usr/bin/sh
txt3()
{
case "$#" in
0)
echo $line ;;
1)
if [ -n "$line" ]
then
echo $line
fi
line=$1" " ;;
*)
line=${line}$@ ;;
esac
}
while read a
do
txt3 $a
done
txt3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2002 09:29 AM
09-15-2002 09:29 AM
Re: scripting help required
Some modifications (better handling of spaces).
#!/usr/bin/sh
txt3()
{
case "$#" in
0)
echo $line ;;
1)
if [ -n "$line" ]
then
echo $line
fi
line=$1 ;;
*)
for b in $@
do
line=${line}" "$b
done
esac
}
while read a
do
txt3 $a
done
txt3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2002 07:33 PM
09-15-2002 07:33 PM
Re: scripting help required
If you don't mind using perl, here is a short one liner-
perl -ne 'chomp; if (/^\d+$/) { print "\n",$a if $a; $a=$_; } else { $a.= " " . $_;
} print $a;' inputfile.txt
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2002 07:46 PM
09-15-2002 07:46 PM
Re: scripting help required
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2002 12:21 AM
09-16-2002 12:21 AM
Re: scripting help required
...using awk:
awk '{if (NF==1 && NR >1)printf("\n",$0)}{printf("%s",$0)}END{print}' file
Rgds, Robin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2002 12:07 AM
09-17-2002 12:07 AM
Re: scripting help required
maybe I read too much into your question, but you could try running the attached script using your input file as par1.
regards,
John K,