- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Scripting help
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
08-02-2004 06:44 AM
08-02-2004 06:44 AM
Scripting help
I want to combine two lines into one line
LABEL1:some output
LABEL2:some output
.
.
Want to print like
LABEL1:output LABEL2: output
Any help is appreciated.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2004 06:48 AM
08-02-2004 06:48 AM
Re: Scripting help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2004 06:57 AM
08-02-2004 06:57 AM
Re: Scripting help
#!/usr/bin/sh
INFILE="/mydir/myfile"
typeset -i10 I=0
cat ${INFILE} | while read X
do
if [[ $((${I} % 2)) -eq 0 ]]
then
echo "${X} \c"
else
echo "${X}"
fi
((I + 1))
done
if [[ $((${I} % 2)) -eq 1 ]]
then
echo
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2004 07:38 AM
08-02-2004 07:38 AM
Re: Scripting help
((I + 1))
should be:
((I += 1))
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2004 07:50 AM
08-02-2004 07:50 AM
Re: Scripting help
awk '{printf("%s", $0)
if( NR%2 == 0)print "" }' filename
HTH
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2004 07:52 AM
08-02-2004 07:52 AM
Re: Scripting help
#print "LABEL1: ${output1} \c"
#print "LABEL2: ${output2}"
This will print:
LABEL1: some output LABEL2: some output
If this isn't what you mean, we could use a little more info on what you are trying to do.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2004 05:09 PM
08-02-2004 05:09 PM
Re: Scripting help
If the data comes from 1 file, then join is not going to help much but maybe 'pr' can do it's trick.
Check out: ps -2 -t -s seperate.txt > combined.txt
The -s changes column based to seperator character based output (default tab).
Here is somehting in AWK actively looking for 'LABEL1:':
awk '/^[A-Z0-9]+:/{if (i++%2) {print one, $0} else {one=$0}}' seperate.txt > combined.txt
Here the part between // actually looks specifically for a line, beginning with (^) a series of once or more (+) characters in the range of A thru Z or 0 - 9 ([...]) followed by a colon (:).
If you just want any old line (like the pr solution) then simplify to:
awk '{if (i++%2) {print one, $0} else {one=$0}}' seperate.txt > combined.txt
If the 'labels' are strictly and only a series of Uppercase characters, followed by a series of numbers at the start of a line then the // becomes: /^[A-Z]+[0-9]+:/
Many more options possible, but you'll have to help us describe them if you can not figure it out yourself.
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2004 06:11 PM
08-02-2004 06:11 PM
Re: Scripting help
Is this what you are looking for!!
# more file1
LABEL1:some output
LABEL2:some output
#
# cat file1 | xargs
LABEL1:some output LABEL2:some output
#
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2004 06:19 PM
08-02-2004 06:19 PM
Re: Scripting help
set -x
# Execute with a filename
i=0
while read line; do
echo -n "$line "
let i=i+1
if [[ $((i%2)) -eq 0 ]]; then
echo ""
fi
done < $1
-- muthu ---
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2004 06:43 PM
08-02-2004 06:43 PM
Re: Scripting help
set -x
# Execute with file - $1 filename
i=1
count=$(cat $1 | wc -l)
while [[ $i -le $count ]]; do
echo `sed -n $i,$(($i+1))p $1`
let i=i+2
done
-- muthu --
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2004 11:55 PM
08-03-2004 11:55 PM
Re: Scripting help
awk '{line1=$0; getline; print line1 " " $0 }' filename
Else If u want to combine many lines into a single line then this will be useful
cat filename | xargs
-Saravanan