- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Scripting question - joining files line by line
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
10-12-2001 12:28 PM
10-12-2001 12:28 PM
I am trying to join two files line by line. The join(1) command chokes due to line length.
Lets say the files have a format comma sep. format like this -
File1
A1,A2,A3,...,A255
1,aaa,aaa,aaa,...,aaa
2,bbb,bbb,bbb,...,bbb
File2
B1,B2,B3,...,B255
1,ccc,ccc,ccc,...,ccc
2,ddd,ddd,ddd,...,ddd
I want to end up with -
A1,A2,...,A255,B1,B2,...,B255
1,aaa,...,aaa,1,ccc,ccc,...,ccc
2,bbb,...,bbb,2,ddd,ddd,...,ddd
Not a straight cat, but a concatenation on a line by line basis.
join chokes, "join: Too many fields in line A1" I don't know enough Perl, :-(
Any ideas??
THX,
Jay
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2001 12:42 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2001 12:46 PM
10-12-2001 12:46 PM
Re: Scripting question - joining files line by line
How about this:
#!/usr/bin/sh
#
F1=/tmp/file1
F2=/tmp/file2
#
while read R1
do
read R2 < $F2
echo $R1 $R2 >> /tmp/output
done < $F1
#
exit 0
#.end.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2001 12:56 PM
10-12-2001 12:56 PM
Re: Scripting question - joining files line by line
As long as each of the files have the same
number of lines you could try the paste.
paste -d file1 file2 > file 3
HTH
-Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2001 01:06 PM
10-12-2001 01:06 PM
Re: Scripting question - joining files line by line
cp file1 file1$$
cp file2 file2$$
for i in `cat file1$$`
do
LINE1=`sed -n '1p' file1$$`
LINE2=`sed -n '1p' file2$$`
echo $LINE1,$LINE2 >> result
sed '1d' file1$$ >> t
mv t file1$$
sed '1d' file2$$ >> t
mv t file2$$
LEN1=`wc -l file1$$|awk '{print $1}' `
LEN2=`wc -l file2$$|awk '{print $1}' `
if [ $LEN1 = 0 ]
then
cat file2$$ >> result
exit
fi
if [ $LEN2 = 0 ]
then
cat file1$$ >> result
exit
fi
done
rm file1$$ file2$$
You may have to replace for with while if the format is not the same and if there are any spaces or tabs in the lines.
PS: I don't know if this works. I don't have a system in front of me. Butyou can use this logic.
-Sri